【问题标题】:Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Cannot read property 'compatMode' of undefined [duplicate]线程“主”org.openqa.selenium.WebDriverException 中的异常:未知错误:无法读取未定义的属性“compatMode”[重复]
【发布时间】:2019-01-04 10:29:11
【问题描述】:

当我在 google chrome 浏览器中运行自动化脚本时,我遇到了以下问题。

代码:

    System.setProperty("webdriver.chrome.driver", 

   "D:\\Selenium\\drivers\\chromedriver.exe");  
    WebDriver driver = new ChromeDriver(cap);

    driver.get(url);
    Thread.sleep(2000);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

    Thread.sleep(2000);
    driver.findElement(By.id("ImgLogo")).click();
    System.out.println("logo was clicked");

    driver.findElement(By.xpath("//input[@id='TxtUserId']")).sendKeys("AUT11");
    driver.findElement(By.xpath("//input[@id='TxtPwd']")).sendKeys("AUT11");

    driver.findElement(By.xpath("//input[@id='btnSecureLogin']")).click();

    driver.quit();
}

错误:

Starting ChromeDriver 2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387) on 
port 25570
Only local connections are allowed.
Jan 04, 2019 3:44:50 PM org.openqa.selenium.remote.ProtocolHandshake 
createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown 
error: Cannot read property 'compatMode' of undefined
 (Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.45.615291 
(ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 6.1.7601 SP1 
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds

请帮我解决这个问题。

【问题讨论】:

  • 你的代码能编译吗?似乎行设置系统属性有错误的斜杠。尝试用这个替换: System.setProperty("webdriver.chrome.driver", "D:/Selenium/drivers/chromedriver.exe");

标签: java selenium


【解决方案1】:

试试这个代码

System.setProperty("webdriver.chrome.driver","C:\\Users\\Desktop\\chromedriver_2.45.exe");  
WebDriver driver = new ChromeDriver();

【讨论】:

  • 这段代码和问题代码有什么区别?
  • 区别在于第一行的能力(WebDriver driver = new ChromeDriver(cap))
  • 我也厌倦了那个。它的工作同样的问题
猜你喜欢
  • 1970-01-01
  • 2014-10-25
  • 2017-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多