java - 线程 "main"org.openqa.selenium.ElementNotInteractableException : element not interactable 中出现异常

标签 java selenium selenium-webdriver css-selectors webdriverwait

我有以下代码:

导入java.util.HashMap; 导入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();
         
        
    }
    }

我收到以下错误:

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

我不明白我怎么错了。 我会提到我正处于开始阶段。 (我还在学习)。 有人可以看一下吗?

最佳答案

您可以尝试使用以下更新的 xpath,希望这能解决您的问题

  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

关于java - 线程 "main"org.openqa.selenium.ElementNotInteractableException : element not interactable 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65035457/

相关文章:

java - 通过itext生成pdf时如何避免单元格中图像过度 float

javascript - ReactJS Selenium 测试

java - 如何模拟 @AfterParameter JUnit 注解?

javascript - Selenium Click() 不适用于 scrapy 蜘蛛

java - 列表 WebElement 始终从下拉列表中选择第一个元素,但我想选择第四个元素

selenium - 使用 TestNG 仅重试特定的失败测试

java - 如何检索weblogic域名主页?

java - h2 上的 hibernate ID 生成器 AUTO_INCREMENT 和集群中的 MySQL

java - JSF访问bean类中的html元素值

javascript - 如何在 Python 中实现 Selenium HTML5 拖放解决方法