Python Selenium return HTML location -
i have simple html table consisting of tr/td. need return exact table row , table column number of exact record. solution should able handle number of rows/columns. find item use:
webdriver.find_element_by_xpath("//*[contains(text(), '8')]")
now need return it's location, far i've been looking attributes value_of_css_property
/ getcssvalue
etc. i'm new selenium, appreciated.
if need locate row containing td
element containing specific text:
element = webdriver.find_element_by_xpath("//tr[contains(td, '8')]")
or, if need locate specific cell (td
element):
element = webdriver.find_element_by_xpath("//td[contains(., '8')]")
then, can location
:
print(element.location)
this give coordinates of element on page.
if need row , column number of cell containing desired text:
table = webdriver.find_element_by_id("mytable") rows = table.find_elements_by_tag_name("tr") row_index, row in enumerate(rows, start=1): cells = row.find_elements_by_tag_name("td") column_index, cell in enumerate(cells, start=1): if "8" in cell.text: print("found match!") print(row_index, column_index) break
Comments
Post a Comment