1

I tried to create a selenium automation project to automate a login page of a website and I could not auto fill out the data in the email section. I have used intelij idea, selenium and firefox-geckodriver as well as used selenium-java-3.141.59 jar file.

When running the automation project the login page is automatically loading. But can't auto fill the username field

The code I used:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.util.concurrent.TimeUnit;

public class testDriver {

    public static void main(String[] args) {
        //setting driver properties
        System.setProperty("webdriver.gecko.driver","C:\\Users\\user\\Documents\\Driver\\Firefox\\geckodriver.exe");
        WebDriver driver =new FirefoxDriver();
        //navigate driver to the website(not mentioned the actual URL here)
        driver.navigate().to("https://accounts.google.com/signin");
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            System.out.println(e);}
            //Enter username
            WebElement username= driver.findElement(By.id("signInFormUsername"));
            username.click();
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            System.out.println(e);}
            username.clear();
            username.sendKeys("Christina");
            WebElement txtbx_username = driver.findElement(By.id("identifierId"));
            txtbx_username.click();
            txtbx_username.clear();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                System.out.println(e);}*/
            driver.close();
            driver.quit();
        }
    }

This is the error I got:

1658413753579   geckodriver INFO    Listening on 127.0.0.1:56968
1658413754419   mozrunner::runner   INFO    Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "--remote-debugging-port" "62365" "--remote-allow-hosts" "localhost" "--remote-allow-origins" "http://localhost:62365/" "-no-remote" "-profile" "C:\\Users\\INTERV~1\\AppData\\Local\\Temp\\rust_mozprofileaE9gCO"
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.
1658413755965   Marionette  INFO    Listening on port 4319
1658413756461   Marionette  WARN    TLS certificate errors will be ignored for this session
Jul 21, 2022 7:59:16 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected upstream dialect: W3C
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element <input id="signInFormUsername" class="form-control inputField-customizable" name="username" type="text"> could not be scrolled into view
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'DESKTOP-5LAN9CC', ip: '192.168.8.100', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.15'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Command: [88684e90-9cc0-49ff-99d9-d979b161ef98, clickElement {id=3fb62dd1-b2a7-4e45-b81a-b23444de5bff}]
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 78.1.0, moz:accessibilityChecks: false, moz:buildID: 20200722151235, moz:geckodriverVersion: 0.31.0, moz:headless: false, moz:processID: 21620, moz:profile: C:\Users\Intervest\AppData\..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Element: [[FirefoxDriver: firefox on WINDOWS (88684e90-9cc0-49ff-99d9-d979b161ef98)] -> id: signInFormUsername]
Session ID: 88684e90-9cc0-49ff-99d9-d979b161ef98
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:257)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:78)
    at testDriver.main(testDriver.java:32)

This is the html element for username

<input id="signInFormUsername" name="username" type="text" class="form-control inputField-customizable" placeholder="Username" autocapitalize="none" required=""> 

Can someone please provide me a solution for this or, provide me a proper tutorial fore selenium-java automation with inteliJ and firefox browser

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Erandi Dilshani
  • 335
  • 1
  • 4
  • 11

1 Answers1

0

This error message...

org.openqa.selenium.ElementNotInteractableException: Element <input id="signInFormUsername" class="form-control inputField-customizable" name="username" type="text"> could not be scrolled into view

...implies that WebElement wasn't within the Viewport when click was invoked.


Solution

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

  • cssSelector:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control.inputField-customizable[name='username'][placeholder='Username']"))).click();
    
  • xpath:

    new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='form-control inputField-customizable' and @name='username'][placeholder='Username']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352