Python Selenium Drop Down Menu Click
i want to select option from a drop down menu, for this i use that : br.find_element_by_xpath('//*[@id='adyen-encrypted-form']/fieldset/div[3]/div[2]/div/div/div/div/div[2]/div/ul/
Solution 1:
You should use Select()
to select an option from drop down as below :-
from selenium.webdriver.support.ui import Selectfrom selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, 10)
element = wait.until(EC.visibility_of_element_located((By.ID, "dwfrm_adyenencrypted_expiryMonth")))
select = Select(element)
select.select_by_value("04")
Edited :- If unfortunately above does not work you can also try using .execute_script()
as below :-
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.ID, "dwfrm_adyenencrypted_expiryMonth")))
driver.execute_script("var select = arguments[0]; for(var i = 0; i < select.options.length; i++){ if(select.options[i].value == arguments[1]){ select.options[i].selected = true; } }", element, "04")
Hope it will work...:)
Post a Comment for "Python Selenium Drop Down Menu Click"