Nikhil srivastav
Nikhil srivastav

Reputation: 11

How to click on a button with href attribute on webpage

I have used the below code to click on login button but it is not working:

Trial 1:

driver.findElement(By.xpath("//a[text()='https://www.luxproflashlights.com/customer/account/login/referer/aHR0cHM6Ly93d3cubHV4cHJvZmxhc2hsaWdodHMuY29tLw%2C%2C/']")).click(); 

Trial 2:

driver.findElement(By.linkText("Log In")).click();

Upvotes: 0

Views: 35

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193088

If the element contains both the href attribute and the text Log In you can use either of the following Locator Strategies:

  • partialLinkText:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Log In"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@href, 'luxproflashlights') and contains(., 'Log In')]"))).click();
    

Upvotes: 1

Related Questions