I can't find the element of the html below.
<span class="tabComboBoxName" id="tab-ui-id-1565209097494" aria-hidden="true">20/07/2019</span>
I've tried the following codes:
elem = browser.find_elements_by_xpath("//class[@id='tab-ui-id-1565209097494']")
elem = browser.find_elements_by_class_name('tabComboBoxName')
elem = browser.find_elements_by_id('tab-ui-id-1565209097494')
For those tries I got an empty list.
The element is a dynamically generated element so to locate the element you need to induce WebDriverWait for the desired visibility_of_element_located()
and you can use either of the following Locator Strategies :
Using CSS_SELECTOR
:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "span.tabComboBoxName[id^='tab-ui-id-']")))
Using XPATH
:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[@class='tabComboBoxName' and starts-with(@id, 'tab-ui-id-')][contains(., '20/07/2019')]")))
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
<iframe>
, if it does - you will need to switch_to() the iframe where the element lives prior to attempting to find it Try using another locator strategy , for instance you can stick to the element text like:
//span[text()='20/07/2019']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.