1

I wanted to automate a web page using webdriver(Python) wherein the script will click on the href link directly in order to navigate to other page. Couple of details in the specific tag:

<span class = "xyz", ui-sref ="abc", href= "/letters/letters_number/"> 
"hdf"
<i class = 'icons'>letters</i>
</span>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Search the stack, it has 100 questions on this topic. – Gaj Julije Feb 08 '22 at 16:51
  • 1
    Thanks, Gaj. But what I have mentioned in the description above, the tag details, I couldn't find a great match. Hence, would need someone's help. –  Feb 08 '22 at 17:09
  • 1
    click the link like you would normally see how the URL looks and append that href to the base URL and then call your webdriver driver.get() to get that page – Andrew Ryan Feb 08 '22 at 17:24

1 Answers1

0

To click() on a the element with the href attribute you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span[href=/letters/letters_number/] i.icons"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@href='/letters/letters_number/']//i[@class='icons']"))).click()
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352