Selenium can't find the elements I'm looking for - Python

Category: python selenium (6 Views)

I'm trying to get the coordinates of a button/text on a website, this will help me automate my day to day work. The problem I encounter when using Selenium is that it can't read the whole HTML code (I think).

website="the website is ServiceNow, I will provide the url only if needed"
path="D:\chrome_driver\executable\chromedriver" #it won't work without this path

#Here I need to login so I will skip this part of the code as I just make use of pyautogui to enter info/press tab and enter. Users need to authenticate with 2FA.

pin=input("Insert the PIN and press ENTER to continue")    #pause in the script until the PIN is inserted

Here are my attempts to scrap the info:

inputElement = driver.find_element(By.XPATH, '//div[@class="list2_cell_background"]')

inputElement = driver.find_element(By.XPATH,'//span[@class="sr-only"]')

inputElement = driver.find_element(By.XPATH,'//div[@style="background-color:orange"]')

inputElement = driver.find_element(By.NAME,'2 - High')

And the last part where I'm supposed to get the coordinates:


To be fair there is so much HTML code (10835 lines), my IDLE shell keeps freezing every 2 seconds if I want to look through it. I used the the following method to get the HTML and inspect it in the shell and I believe nothing is missing but for some reason it can't find the xpath or name I want.

html = driver.page_source

This is the part of the HTML I'm looking for

<td class="vt" ng-non-bindable="">
  <span class="sr-only"></span>
  <div class="list2_cell_background" style="background-color:orange"></div>
  "2 - High"

This is a photo with some info of what I'm looking for. I need to get coordinates of this location on the page

And here is the error I get:

Traceback (most recent call last):
File "C:\Users\user\Desktop\", line 40, in <module>
inputElement = driver.find_element(By.XPATH,'//div[@class="list2_cell_background"]')
File "D:\python\python310\lib\site-packages\selenium\webdriver\remote\", line 855, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "D:\python\python310\lib\site-packages\selenium\webdriver\remote\", line 428, in execute
File "D:\python\python310\lib\site-packages\selenium\webdriver\remote\", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="list2_cell_background"]"}
(Session info: chrome=105.0.5195.127)
Ordinal0 [0x002FDF13+2219795]
Ordinal0 [0x00292841+1779777]
RtlGetAppContainerNamedObjectPath [0x77947B2E+238]
(No symbol) [0x00000000]

I've tried this on other websites and it works but I'm not sure what's the issue here. And sorry for the long post, I don't know how to make it more clear than this.

🔴 No definitive solution yet