Search code examples
pythonseleniumxpathelementpartiallinktext

How to click on the E-Paper link of the first left element using Selenium Python


I used chrome inspect>select an element in the page then select it and copy xpath address

and in python use it for click in element but just refresh page and not work

Website url: https://zeitung.faz.net/

and I need to click on E-Paper using xpath:

driver.find_element_by_xpath("/html/body/main/div[1]/div/div[1]/div[2]/ul/li[1]/div[1]/div[2]/a[2]").click()

But not click.


Solution

  • Try either of the following:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "E-Paper"))).click()
    

    or

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[normalize-space()='E-Paper']"))).click()