I am getting an error saying - element not interactable in selenium, what should I do?

504    Asked by MeganHudson in Cyber Security , Asked on Oct 18, 2022
Test Code
 @Test (priority=6)
     
     public void Testcase6() throws InterruptedException {
            driver.get("https://test.ninjafocus.com/");
            driver.manage().deleteAllCookies();
            Thread.sleep(1000);
            driver.manage().window().maximize();
            WebDriverWait wait = new WebDriverWait(driver,30);
            WebElement element= wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@href, 'https://test.ninjafocus.com/login/')]")));
            ((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
            driver.findElement(By.xpath("//a[contains(text(),'Sign Up here')]")).click();
            Thread.sleep(1000);
            driver.findElement(By.xpath("//input[@id='txtEmail']")).sendKeys("gatesix77+wk17@gmail.com");
            Thread.sleep(1000);
            driver.findElement(By.xpath("//input[@id='txtPassword']")).sendKeys("Gate6@123");
            Thread.sleep(1000);
            driver.findElement(By.xpath("//input[@id='influencerCode']")).sendKeys("XSW60X");
            Thread.sleep(1000);
            driver.findElement(By.xpath("//input[@name='signUpSubmit']")).click();
            Thread.sleep(10000);    
            driver.get("https://accounts.google.com/signin/v2/identifier?continue=https://mail.google.com/mail/&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin");
            Thread.sleep(2000);
            driver.findElement(By.xpath("//input[@id='identifierId']")).sendKeys("gatesix77@gmail.com");
            Thread.sleep(2000);
            driver.findElement(By.xpath("//div[@id='identifierNext']/div/button/div[2]")).click();
            Thread.sleep(3000);
            driver.get("https://accounts.google.com/signin/v2/challenge/pwd?");
            Thread.sleep(10000);
            WebElement element1 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@type='password']")));
            ((JavascriptExecutor)driver).executeScript("arguments[0].click();", element1);
            driver.findElement(By.xpath("//input[@type='password']")).sendKeys(""); /for now removed this you can consider as use.
            Thread.sleep(5000);
            driver.findElement(By.xpath("//div[@id='passwordNext']/div/button/div[2]")).click();
            Thread.sleep(1000);
     }
     @AfterTest
     public void quit() {
         //driver.close();
     }
}
I'm getting the following error:
  (Session info: chrome=88.0.4324.190)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'DESKTOP-P5H3V2F', ip: '10.1.0.154', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 88.0.4324.190, chrome: {chromedriverVersion: 88.0.4324.96 (68dba2d8a0b14..., userDataDir: C:UsersGatesixAppDataLo...}, goog:chromeOptions: {debuggerAddress: localhost:56315}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 65ca95e47d2ddad8f18f78ba6806833c


Answered by Joshua Smith

The element not tractable or not visible or covered by another opened element (for example dropdown, modal window) error is coming due to the exact same problem. Check it out https://stackoverflow.com/questions/44119081/how-do-you-fix-the-element-not-interactable-exception Make sure your element is visible before clicking it or sending text if it is an input field.


You use:

((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
to click. As I understand it is because standard click() does not work. JavascriptExecutor most likely won't work if the element is not visible.

Your Answer

Interviews

Parent Categories