[🐛 Bug]: XPATH div[10+] cannot retrieve text.
See original GitHub issueWhat happened?
When retrieving absolute and relative XPATH nodes, a div greater than 9 will return an empty text value.
How can we reproduce the issue?
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")
driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))
driver.get("https://www.cntower.ca/lighting-schedule/")
colour9 = driver.find_element(by=By.XPATH, value='//*[@id="block-de-theme-content"]/div/article/div/div/div/div[1]/div/div/div/div/div/div[9]/article/div[1]/div[2]')
colour10 = driver.find_element(by=By.XPATH, value='//*[@id="block-de-theme-content"]/div/article/div/div/div/div[1]/div/div/div/div/div/div[10]/article/div[1]/div[2]')
print(colour9.text) #returns a string
print(colour10.text) #returns an empty string
driver.quit()
Relevant log output
N/A
Operating System
Ubuntu / Multiple
Selenium version
Python 3.9.6
What are the browser(s) and version(s) where you see this issue?
Chromium 93.0.4577.82
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 93.0.4577.82
Are you using Selenium Grid?
No
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Xpath is unable to find text - Stack Overflow
As this text has no particular div I am getting difficulty to get it. Selenium code I tried driver.findElement(By.xpath(".//*[@id='filterInfo']/ ...
Read more >Help with Screen Scraping Problem - UI.Vision RPA
Hello, I am having the hardest time finding a solution to this problem. I am trying to screen scrape the data from a...
Read more >Unable to locate Text element using XPath in Selenium [closed]
Sometimes elements are not accessible directly. So, in test automation services we try including the parent div to locate that element.
Read more >How to verify a tooptip which ist hidden in a div-section?
Hello, I'm trying to verify a tooltip in an Angular website. Its not possible to acess this tooltip with the Object Spy.
Read more >Robot cannot find a locator saved from Katalon Studio 7 #3389
Hi,. I am stuck trying to figure out why is it that robot returns error: "Element with locator 'xpath=//div[@id='root']/div/div[2]/div[2]/div/ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I think there’s just something in your absolute XPath tripping you up.
Loop over this (or tweak for whatever you’re actually trying to capture):
Feel free to reach us at https://www.selenium.dev/support/#ChatRoom
@tallmega it looks to me like the tiles are not properly rendered / visible here until scrolling occurs on that particular URL so I’m not sure it’s a particular xpath & div index of
>9, the elements are found but their visible text is likely empty? https://w3c.github.io/webdriver/#get-element-text. Whether thats:I am not so sure 😉, need to do a bit of digging.
For example if you scroll to the bottom of the page, then query all the texts, likely prints out correctly.
Naive example to prove out the theory: