Home > front end >  Python Selenium get value of tooltip text with javascript website
Python Selenium get value of tooltip text with javascript website

Time:05-31

I am new to Selenium. Read through many historical posts and try to retrieve tooltip text but fail...

X path (for "col_issued_shares" should be correct as it is directly copy like below screen:

Screenshot 1

The result is SyntaxError: invalid syntax. My expected output is Issued Shares 20,428,671,958 ( as at 27 May 2022) . But when I view source , it shows toolkit text.

Screenshot 2

Screenshot 3

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


s=Service(r'C:\Users\chromedriver.exe')
driver = webdriver.Chrome(service=s)
url='https://www.hkex.com.hk/Market-Data/Securities-Prices/Equities/Equities-Quote?sym=5&sc_lang=en'
driver.get(url)

element = driver.find_element(By.XPATH, "//*[@id="lhkexw-quoteequities"]/div[2]/div[3]/div[2]/div/div[2]/div[1]/div[1]/span[2]/span")

Can someone help? Thanks a lot

CodePudding user response:

Try xpath //*[@id='lhkexw-quoteequities']/div[2]/div[3]/div[2]/div/div[2]/div[1]/div[1]/span[2]/span

Actually you are enclosing xpath with double quotes ("). So in xpath you should use single-quote (') for @id=''.

  • Related