0

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

1 Answer 1

1

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=''.

Sign up to request clarification or add additional context in comments.

4 Comments

changed and run below is result. <selenium.webdriver.remote.webelement.WebElement (session="b2beaba3610734bf8684c8c0f92319d8", element="44c5736b-847d-400c-bf79-97086acd8ccb")>
How can I get this result?? Issued Shares 20,428,671,958 ( as at 27 May 2022)
@Jodie I checked the screenshot that you have attached. As per that, your xpath should be //span[contains(@class, 'col_issued_shares')] To print the text print(driver.find_element(By.XPATH, "//span[contains(@class, 'col_issued_shares')]").text)
You are right. Now I get result :20,428,671,958 (as at 27 May 2022), BIG THANKS!!. Next step , I will explore ways to search a list of securities and print out their issued shares into csv format. Will keep you posted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.