3

I cant get automate creating account with group_option selected using selenium with python. I tried several solutions but still it doesn't work. the website is form .php please see codes i used. Im on Linux not Windows.

test-1

driver = webdriver.PhantomJS()

select = Select(driver.find_element_by_name('group_option[]'))
select.select_by_value("Test")
driver.find_element_by_name("submit").click()

website.php

<select onchange="javascript:setStringText(this.id,'group')" id="usergroup" name="group_option[]" class="form" tabindex="105">
    <option value="">Select Groups</option>
    <option value=""></option>  
    <option value="Test"> Test </option>
    <option value="Test1"> Test1 </option>
</select>
2
  • @pguardiario im using Ubuntu server headless. what can you recommend? Commented Nov 26, 2018 at 10:34
  • I always use chrome because I like the console for debugging Commented Nov 26, 2018 at 22:34

3 Answers 3

2

To select the option with text as Test you can use the following solution:

select = Select(driver.find_element_by_xpath("//select[@class='form' and @id='usergroup'][contains(@name,'group_option')]"))
select.select_by_value("Test")

Update

As you are still unable to select from the dropdown-list as an alternative you can induce WebDriverwait and use either of the following solutions:

  • Option A:

    select = Select(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//select[@class='form' and @id='usergroup'][contains(@name,'group_option')]"))))
    select.select_by_value("Test")
    
  • Option B:

    select = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@class='form' and @id='usergroup'][contains(@name,'group_option')]"))))
    select.select_by_value("Test")
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
Sign up to request clarification or add additional context in comments.

2 Comments

i tested the code and it didn't work. i don't know whats wrong
@nicollette16 Checkout my updated answer and let me know the status.
0
from selenium import webdriver
from selenium.webdriver.support.ui import Select

driver = webdriver.Firefox()
driver.get('url')

select = Select(driver.find_element_by_id('usergroup'))

select by value

select.select_by_value('Test')

1 Comment

im using driver = webdriver.PhantomJS() .. i tried your solution and still cant get result with group option. thanks
0
from selenium import webdriver
from selenium.webdriver.support.ui import Select

driver = webdriver.Firefox()
driver.get('url')

select = Select(driver.find_element_by_xpath("//select[@id='usergroup']"))

# select by visible text
select.select_by_visible_text('Test')
 OR
# select by value 
select.select_by_value('Test')

1 Comment

tested this, i think i saw this same code from other solution and it didn't work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.