0

I am trying to login a page.

I entered the e-mail & password inputs by element.sendKeys() without any error.

After that I need to click the 'loginButton' button. But the button is defined as non keyboard-focusable.

When I run the automation, the button is clicked. But the automation is not continue with the next page (main page); just reloads the same page with empty inputs.

I tried several ways to click the button and also tried to enter by using 'ENTER' key;

// **1.**
 loginButton.click();

// **2.**
 robot.keyPress(KeyEvent.VK_ENTER);

// **3.**
 Actions act = new Actions(dDriver);
 act.moveToElement(driver.findElement(By.id("loginButton"))).click().build().perform();

// **4.**
 JavascriptExecutor executor;

All of them seems that I can click the button but after that as I mentioned, the page is reloaded, not continue with the next page.

What else can I try?

  • Please give a link to the site / URL you are trying to automate. – Tal Angel Feb 09 '22 at 14:37
  • What about shoot out js `document.submit()`? – pburgr Feb 09 '22 at 15:30
  • Here is the site: https://www.n11.com/giris-yap @TalAngel – Test_Account Feb 09 '22 at 16:32
  • Are you entering a correct Username and correct Password via the code? – Tal Angel Feb 09 '22 at 16:48
  • Yes, I'm sure; because when I am entering manually, it is correct. By the way, if I enter wrong, the warning/error message should be displayed; like, 'The E-mail Address or password is wrong.'. Also, I tried with the wrong inputs in automation, when I tried it, the page is reloaded again as same way. @TalAngel – Test_Account Feb 09 '22 at 16:55

2 Answers2

0

A problem I can think about is that you are typing the information too fast and hit the login button right away.

Try to wait before clicking the Login button 0.3 seconds:

Thread.Sleep(300);

Or even a full second:

Thread.sleep(1000);

Tell me if this solves your issue.

Also, the site might be disabled for automation code so add these to your ChromeOptions:

ChromeOptions options = new ChromeOptions(); 
options.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"}); 
WebDriver driver = new ChromeDriver(options); 

Or

options.addArguments("disable-infobars");
Tal Angel
  • 1,301
  • 3
  • 29
  • 63
0

To click() on the element Giriş Yap you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following locator strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.green_flat#loginButton"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='green_flat' and @id='loginButton'][text()='Giriş Yap']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352