I’m trying to get a table from a dynamic webpage using selenium but it’s giving me issues. This is the Python code:
from selenium import webdriver
url = 'https://draft.shgn.com/nfc/public/dp/788/grid'
driver = webdriver.Chrome('C:chromedriver_win32chromedriver.exe')
global_dynamicUrl = "https://draft.shgn.com/nfc/public/dp/788/grid"
driver.get(global_dynamicUrl)
table_area = driver.find_element("xpath", '//*[@id="result"]/table')
table_entries = table_area.find_elements_by_tag_name("tr")
print(len(table_entries))
driver.close()
But this produces a "NoSuchElementException" Error.
What am I doing wrong?
Thanks in advance.
3
Answers
Atleast i don’t see the above-mentioned locator in website, you can try something similar like below.
From the URL you have provided, I don’t see any web element in the DOM matching your
XPath
expression –//*[@id="result"]/table
. So the reason for yourNoSuchElementException
is the incorrectXPath
with which you are trying to get the desired element.Below code locates table’s column headers: (Returns one
tr
)Below code locates all other
tr
nodes of the table: (Returns 30tr
)There is no element with an ID of "result" on the page so that’s why your locator isn’t working. There is only one TABLE tag on the page so you can simplify your code down to