I want to make selenium select a choise from box
<li data-dial-code="1" data-country-code="us"><div ><div ></div></div><span >United States</span><span > 1</span></li>
I want to change the data-dial-code
can I do this? and thanks
CodePudding user response:
The click on the element:
<li data-dial-code="1" data-country-code="us">
You need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li.country[data-country-code='us'] div.us"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='country' and @data-country-code='us'][.//span[text()='United States']]"))).click()
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