2

I have the following code :

import java.util.HashMap; import java.util.Map;

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.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

public class LoginToThePortal {
     public static void main(String[] args) throws InterruptedException
     {
    
    
         System.setProperty("webdriver.chrome.driver","C:\\chromedriver\\chromedriver.exe");
         WebDriver driver=new ChromeDriver();
         driver.manage().window();
         driver.get("");
         Thread.sleep(2000);
         WebElement username=driver.findElement(By.id("sfdc_username_container"));
         Thread.sleep(5000);
         WebElement password=driver.findElement(By.id("sfdc_password_container"));
         WebElement login=driver.findElement(By.xpath("//*[@id=\"centerPanel\"]/div/div[2]/div/div[2]/div/div[3]/button/span"));
         username.sendKeys("");
         password.sendKeys("");
    
          login.click();
         
        
    }
    }

And I have received the following error:

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: element not interactable.

And I don't understand how I have wrong. I will mention that I am at the begin. (I m still learning). Can someone have a look?

Test
  • 47
  • 1
  • 6

2 Answers2

2

Can you try with the below updated xpath's, Hope this will resolve your issue

  System.setProperty("webdriver.chrome.driver","C:\\chromedriver\\chromedriver.exe");
    WebDriver driver=new ChromeDriver();
    driver.manage().window();
    driver.get("https://qa-advisor.cs105.force.com/s/login/");
    Thread.sleep(2000);
    WebElement username = driver.findElement(By.xpath
           ("//div[@id='sfdc_username_container']//child::div/input[1]"));
    Thread.sleep(5000);
    WebElement password = driver.findElement(By.xpath
           ("//div[@id='sfdc_password_container']//child::div/input[1]"));
    WebElement login = driver.findElement(By.xpath
           ("//button[@class='slds-button slds-button--brand loginButton uiButton- 
                         -none uiButton']//child::span"));
    username.sendKeys("test");
    password.sendKeys("test");
    login.click();

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
YaDav MaNish
  • 1,260
  • 2
  • 12
  • 20
1

To send a character sequence to the Username and Password field you need to use WebDriverWait for the elementToBeClickable() and you can use the following based Locator Strategies:

driver.get("https://qa-advisor.cs105.force.com/s/login/");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div#sfdc_username_container input[placeholder='Username']"))).sendKeys("Test");
driver.findElement(By.cssSelector("div#sfdc_password_container input[placeholder='Password']")).sendKeys("Test");

Browser Snapshot:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352