1

I am attempting to click on 'Log in' but my Selenium code isn't working. Below is the HTML code.

<span class="css-14krylx-text-text-fullPageText-FormFooter">Already have a Times account? 
<span tabindex="0" data-testid="switch-to-login" class="css-dip6gw-link-link-FormFooter">Log in</span></span>

What I attempted so far and did not work?

  1. driver.findElement(By.cssSelector("[data-testid='switch-to-login'")).click();

  2. driver.findElement(By.xpath("//span[@data-testid='switch-to-login'")).click();

  3. driver.findElement(By.cssSelector("/.css-dip6gw-link-link-FormFooter'")).click();

Is there any other approach?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
skota
  • 25
  • 1
  • 6

1 Answers1

0

The desired element is a dynamic element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span[class$='text-text-fullPageText-FormFooter'] span[class$='link-link-FormFooter'][data-testid='switch-to-login']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[contains(@class, 'text-text-fullPageText-FormFooter')]//span[contains(@class, 'link-link-FormFooter') and text()='Log in']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Hello DebanjanB - the cssSelector approach appears to have worked. Thanks so much. You are awesome. – skota Apr 29 '19 at 00:11