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 = ‘https://my.te.eg/offering/usage’

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

browser.get(url)

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()”)]

print(remain_no)

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 “[]”.

0
X 5 أشهر 2022-07-10T12:04:47+03:00 0 إجابة 1 مشاهدات مبتدئ 0

‫أضف إجابة

تصفح
تصفح

مجهول يجيب