How to handle the a tag in selenium

499 Views Asked by At

I am facing the problem for below tag in selenium

HTML Code is :

<a data-v-4sa1sads href='#' class='second'>Register</a>

I tried using LinkText, PartialLinkText, CSS selector, Xpath but it is always showing an error that element click is intercepted.

How to handle this.

1

There are 1 best solutions below

0
On

To click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using and linkText:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Register"))).click();
    
  • Using and XPATH:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='second' and text()='Register']"))).click();
    
  • Using and LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Register"))).click()
    
  • Using and CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.second[href]"))).click()
    
  • Note : For python clients 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
    

References

You can find a couple of relevant detailed discussions on ElementClickInterceptedException in: