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);
    });
5
  • Are you getting any error in the console? Commented Jun 4, 2019 at 22:19
  • Have you tried to check if the element identified with the locator using findElements? Commented Jun 4, 2019 at 22:20
  • @supputuri, no it does not work Commented Jun 4, 2019 at 23:02
  • meaning either xpath is not correct or it may be in some iframe. Can you check both the conditions in the chrome dev tools. Commented Jun 4, 2019 at 23:22
  • @supputuri i do not think there is an iframe. can you check here - ca.letgo.com/en Commented Jun 4, 2019 at 23:34

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.