Selenium returns “[]” when trying to print text found by xpath


يرجى شرح بإيجاز لمإذا تشعر أنك ينبغي الإبلاغ عن هذا السؤال.


I have this extension that ensures the xpath is correct, so as far as the xpath validity goes, it should be correct. When I attempt to find it using selenium and then try to print the variable in which I have scrapped the xpath address for I just end up with a “[]” in console. Trying removing /text() and adding .text in print would return me an attribute error. I don’t understand why nothing would return.

from selenium import webdriver
from csv import DictReader
import time

url = ‘’

browser = webdriver.Chrome(executable_path=r’C:UsersUserDesktopwe_internetchromedriver.exe’)


print(“Number: “)
input(“Enter done when done writing password and web loaded”)

remain_no = browser.find_elements_by_xpath(“/html/body/app-root/div/div[1]/app-offering/app-usage/div/div/p-card/div/div/div/div[1]/div[1]/app-gauge/div/span[1]/text()”)
#[link.get_attribute(‘outerHTML’) for link in browser.find_elements_by_xpath(“/html/body/app-root/div/div[1]/app-offering/app-usage/div/div/p-card/div/div/div/div[1]/div[1]/app-gauge/div/span[1]/text()”)]


Here is an image of the html page I’m trying to scrape info from, and as you can see above, the xpath address shows the result with the number in result area. In the code you may have noticed a different attempt at capturing outerHTML but I still end up with the same result an empty “[]”.

‫أضف إجابة


مجهول يجيب