Cannot Find Table Element From Div Element In Selenium Python
Solution 1:
Your observation seems to be near perfect. As per the HTML within During Inspect snapshot which you have shared, The element with text as Taxes Due is highlighted.
While within the While viewing the source code snapshot which you have extracted through Selenium, possibly the Page Source was pulled out even before the child elements have completely rendered within the DOM Tree:
Hence the child elements within <div id='totals'></div>
are not present withi the Page Source.
The relevant HTML in text format would have help to construct a canonical answer. However, to get the total number of <tr>
elements you need to induce WebDriverWait for the visibility_of_all_elements_located()
and you can use either of the following Locator Strategies:
Using
XPATH
:print(len(WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//table/tbody//tr[@class='hasLabel'][./td[@class='label']]")))))
Note : You have to add the following imports :
from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC
Post a Comment for "Cannot Find Table Element From Div Element In Selenium Python"