Selenium, Python Dynamic Table
I'm creating a robot with selenium that get all info from agencies in Brasil, i've alredy done the permutation click between all States and counties, all i have to do now's click
Solution 1:
Try this xPath:
//table[@class = 'dadosAgencia']//tr
It would be like this:
elements = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located(
(By.XPATH, "//table[@class = 'dadosAgencia']//tr")))
it gives you a list of all elements located. To print the text of each element you can use this:
for element in elements:
print(element.text)
Note: you have to add some imports:
from selenium.webdriver.supportimport expected_conditions asECfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.support.waitimportWebDriverWait
Solution 2:
Try this XPath for the table:
//table[@class = 'dadosAgencia']
First, find table elements:
table_elements = WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located(
(By.XPATH, "//table[@class = 'dadosAgencia']")))
Iterate through the table:
for table_element in table_elements:
for row in table_element.find_elements_by_xpath(".//tr"):
print(row.text)
Post a Comment for "Selenium, Python Dynamic Table"