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>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
nicollette16
  • 57
  • 1
  • 8

3 Answers3

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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
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')
min2bro
  • 4,509
  • 5
  • 29
  • 55
  • im using driver = webdriver.PhantomJS() .. i tried your solution and still cant get result with group option. thanks – nicollette16 Nov 26 '18 at 07:05
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')
Kaushik
  • 140
  • 11