1

When you hover over the i you get a popup menu.

no hover

hover

I want to get the last item of the popup 3,0 using Python's Selenium.

But however, it's not working for me. What do I do wrong?

a = driver.find_element(By.XPATH, '//*[@id="articlelist"]/form/div[1]/div[2]/div/div/span/div/div[3]/div[2]').text
print(a)

HTML Snapshot: Website code

Full website code for download: we.tl/t-dZexrOqPU8

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • please do not post a picture of the HTML ... post the HTML text instead – jsotola Feb 17 '22 at 16:57
  • Added the HTML as download :) Thx! – hallowelt444 Feb 17 '22 at 17:01
  • that is worse ... why should anyone here have to go to another website to see what you are talking about? ... questions here should be self contained ... even the pictures should be added as a picture, not as a link – jsotola Feb 17 '22 at 17:03
  • 1
    I'm new to stackoverflow, I can't post pictures directly :/ – hallowelt444 Feb 17 '22 at 17:04
  • @hallowelt444, please post your code in your query. It is generally untrustworthy to download from other website. Hope you can understand. If possible (and if there is no login involved), you may provide the website link too. – Anand Gautam Feb 17 '22 at 17:49

1 Answers1

0

To print the text 3,0 you can use either of the following locator strategies:

  • Using xpath and text attribute:

    print(driver.find_element(By.XPATH, "//div[@class='subinfo']/div[@class='art_popup_infobox']/div[@class='art_popup_line_wrapper'][./div[starts-with(., 'Durchmesser')]]//div[@class='art_popup_info']").text)
    

Ideally to extract the text 3,0 you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:

  • Using XPATH and get_attribute("innerHTML"):

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='subinfo']/div[@class='art_popup_infobox']/div[@class='art_popup_line_wrapper'][./div[starts-with(., 'Durchmesser')]]//div[@class='art_popup_info']"))).get_attribute("innerHTML"))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

You can find a relevant discussion in How to retrieve the text of a WebElement using Selenium - Python


References

Link to useful documentation:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352