I'm looking for some numbers on https://tnnslive.com/
The numbers I'm looking for on tnnslive.com:

If I copy the xpath in Chrome, I get:
//*[@id="root"]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div/div[1]/div/div[1]/div/div/div/div/div[3]/div/div/div/div[7]/div/div[2]
If I run the following code:
from selenium import webdriver
# Start a new Chrome browser session
driver = webdriver.Chrome(executable_path="PATH_TO_CHROMEDRIVER")
# Navigate to the desired URL
driver.get('https://tnnslive.com/match/VDDGj17PodORnq62YwQk')
# Find the element by its XPath and print its text
element = driver.find_element("xpath", '//*[@id="root"]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div/div[1]/div/div[1]/div/div/div/div/div[3]/div/div/div/div[7]/div/div[2]')
# Close the browser
driver.quit()
the error occurs:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="root"]/div/div/div/div/div/div/div/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div/div[1]/div/div[1]/div/div/div/div/div[3]/div/div/div/div[7]/div/div[2]"}
(Session info: chrome=115.0.5790.171)
Why? How can I solve this issue?
To print the text associated with 1st Serve Points Won for the first player within the website you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:
Using XPATH,
following-siblingand text attribute:Using XPATH,
followingandget_attribute("innerHTML"):Console output:
Note : You have to add the following imports :
References
Link to useful documentation:
get_attribute()methodGets the given attribute or property of the element.textattribute returnsThe text of the element.