Reputation: 95
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.
Upvotes: 0
Views: 139
Reputation: 168002
<iframe>
, if it does - you will need to switch_to() the iframe where the element lives prior to attempting to find itTry using another locator strategy, for instance you can stick to the element text like:
//span[text()='20/07/2019']
Upvotes: 0
Reputation: 193058
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
Upvotes: 1