Reputation: 105
I’m a python newbie but recently tried to learn Selenium.
The webpage I’m using is: https://securereg3.prometric.com/Welcome.aspx?msg=EMExpSes
For some reason, it will not select “STEP2” from this drop down list, what should I do? Please help
This is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import time
PATH = 'C:\Program Files (x86)\chromedriver.exe'
driver = webdriver.Chrome(PATH)
driver.get('https://securereg3.prometric.com/Welcome.aspx')
driver.find_element_by_id("masterPage_cphPageBody_rbnProfLisc").click()
prog = Select(find_element_by_id("masterPage_cphPageBody_ddlPrograms"))
time.sleep(1)
prog.select_by_visible_text("STEP2")
Upvotes: 0
Views: 540
Reputation: 193058
The website https://securereg3.prometric.com/Welcome.aspx won't populate the <option>
items within STEP 2 unless you select the options from the radiobutton and the drop-down-menu within STEP 1.
To click on the Radio Button with text as Academic, Professional Licensure & Certification, Government, and Corporate Programs and select the option A. Electrician ELECP and then to <select>
the option UNITED STATES you need to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using CSS_SELECTOR
:
driver.get('https://securereg3.prometric.com/Welcome.aspx')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#masterPage_cphPageBody_rbnProfLisc"))).click()
select1 = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select#masterPage_cphPageBody_ddlPrograms[name^='masterPage']"))))
select1.select_by_value("ELECP")
select2 = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "select#masterPage_cphPageBody_ddlCountry"))))
select2.select_by_visible_text("UNITED STATES")
Using XPATH:
driver.get('https://securereg3.prometric.com/Welcome.aspx')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='masterPage_cphPageBody_rbnProfLisc']"))).click()
select1 = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='masterPage_cphPageBody_ddlPrograms']"))))
select1.select_by_value("ELECP")
select2 = Select(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='masterPage_cphPageBody_ddlCountry']"))))
select2.select_by_visible_text("UNITED STATES")
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
from selenium.webdriver.support.ui import Select
Browser Snapshot:
Upvotes: 0
Reputation: 7563
You miss driver.
in this line:
prog = Select(find_element_by_id("masterPage_cphPageBody_ddlPrograms"))
It's should:
prog = Select(driver.find_element_by_id("masterPage_cphPageBody_ddlPrograms"))
Upvotes: 2