Skip to main content
added 79 characters in body
Source Link
Cynic
  • 235
  • 2
  • 3
  • 14

This is working for me using UI's Select option. e.g.:

from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()

# Locate the Sector and create a Select object
select_element = Select(driver.find_element_by_css_selector(".form-control"))
# this will print out strings available for selection on select_element, used in visible text below
print [o.text for o in select_element.options]  
# theseselect areby string-svisible text
select_element.select_by_visible_text("Low Priority")
# or select by value
select_element.select_by_value('0')
# or select by option index
select_element.select_by_index(1)

Documentation here and some credit to Daniel Abel here.

I'm a bit concerned your error may be coming from somewhere else as the error you're getting is selenium unable to find an element with the class of ng-valid, which isn't included in your example selenium code. Also, with Angular be sure to throw in a wait for the angular page to load. Like:

from selenium.webdriver.support.ui import WebDriverWait # Import at top of file
from selenium.webdriver.support import expected_conditions as EC

# Selenium waits for the page to load, but not necessarily the angular app
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located('ng-valid'))

You may want to use protractor anyway as it has some custom locators for angular and will wait for ng-app to load by default.

This is working for me using UI's Select option. e.g.:

from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()

select_element = Select(driver.find_element_by_css_selector(".form-control"))
print [o.text for o in select_element.options] # these are string-s
select_element.select_by_visible_text("Low Priority")
# or 
select_element.select_by_value('0')
# or 
select_element.select_by_index(1)

Documentation here and some credit to Daniel Abel here.

I'm a bit concerned your error may be coming from somewhere else as the error you're getting is selenium unable to find an element with the class of ng-valid, which isn't included in your example selenium code. Also, with Angular be sure to throw in a wait for the angular page to load. Like:

from selenium.webdriver.support.ui import WebDriverWait # Import at top of file
from selenium.webdriver.support import expected_conditions as EC

# Selenium waits for the page to load, but not necessarily the angular app
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located('ng-valid'))

You may want to use protractor anyway as it has some custom locators for angular and will wait for ng-app to load by default.

This is working for me using UI's Select option. e.g.:

from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()

# Locate the Sector and create a Select object
select_element = Select(driver.find_element_by_css_selector(".form-control"))
# this will print out strings available for selection on select_element, used in visible text below
print [o.text for o in select_element.options] 
# select by visible text
select_element.select_by_visible_text("Low Priority")
# or select by value
select_element.select_by_value('0')
# or select by option index
select_element.select_by_index(1)

Documentation here and some credit to Daniel Abel here.

I'm a bit concerned your error may be coming from somewhere else as the error you're getting is selenium unable to find an element with the class of ng-valid, which isn't included in your example selenium code. Also, with Angular be sure to throw in a wait for the angular page to load. Like:

from selenium.webdriver.support.ui import WebDriverWait # Import at top of file
from selenium.webdriver.support import expected_conditions as EC

# Selenium waits for the page to load, but not necessarily the angular app
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located('ng-valid'))

You may want to use protractor anyway as it has some custom locators for angular and will wait for ng-app to load by default.

Source Link
Cynic
  • 235
  • 2
  • 3
  • 14

This is working for me using UI's Select option. e.g.:

from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()

select_element = Select(driver.find_element_by_css_selector(".form-control"))
print [o.text for o in select_element.options] # these are string-s
select_element.select_by_visible_text("Low Priority")
# or 
select_element.select_by_value('0')
# or 
select_element.select_by_index(1)

Documentation here and some credit to Daniel Abel here.

I'm a bit concerned your error may be coming from somewhere else as the error you're getting is selenium unable to find an element with the class of ng-valid, which isn't included in your example selenium code. Also, with Angular be sure to throw in a wait for the angular page to load. Like:

from selenium.webdriver.support.ui import WebDriverWait # Import at top of file
from selenium.webdriver.support import expected_conditions as EC

# Selenium waits for the page to load, but not necessarily the angular app
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located('ng-valid'))

You may want to use protractor anyway as it has some custom locators for angular and will wait for ng-app to load by default.