2

I am not able to click the login button, my code is correct and there is no iframe or window:

const { Builder, By, Key, until } = require('selenium-webdriver');
const { expect } = require('chai');

describe('SignupTest', () => {
    const driver = new Builder().forBrowser('chrome').build();

    it('signup with valid email and valid password', async () => {
        await driver.get('https://ca.letgo.com/en');
        const loginButton = driver.findElement(By.xpath("//button[contains(.,'Log In')]"));
        driver.execute("arguments[0].click()",loginButton)
        //await driver.findElement(By.xpath("//button[contains(.,'Log In')]")).click();
        //name=email
        //name=password
        //name=name
        //xpath=//span[contains(.,'Sign Up')]
        //await driver.sleep(20000);
    });
AppyGG
  • 366
  • 1
  • 6
  • 11
ccva
  • 23
  • 3

2 Answers2

1

If your goal is using javascript for running the selenium means. i suggest you using nightwatch js which is uses the selenium and node js.

In your case you can do the below.

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));

or

wait.until(ExpectedConditions.elementToBeClickable(By.id<locator>));

You can also check the visibity before click using isDisplay() . If it prints true then perform the click action.

supputuri
  • 12,238
  • 2
  • 14
  • 34
udhaya kumar
  • 126
  • 10
0

The element with text as Log In is actually within a child <span> tag (of the <button> tag) and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    button[data-test='login'][data-testid='login']>span
    
  • Using XPATH:

    //span[text()='Log In']
    

Note: You need to induce WebDriverWait while you attempt to invoke click() on the element with text as Log In.

DebanjanB
  • 118,661
  • 30
  • 168
  • 217