Selenium 打开Gmail时,出现以下错误-预期[object Undefined]Undefined为字符串

Selenium 打开Gmail时,出现以下错误-预期[object Undefined]Undefined为字符串,selenium,selenium-webdriver,Selenium,Selenium Webdriver,错误日志 错误日志 线程“main”java.lang.NoSuchMethodError中出现异常:com.google.common.base.premissions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V 位于org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136) 访问org.openqa.selenium

错误日志


错误日志 线程“main”java.lang.NoSuchMethodError中出现异常:com.google.common.base.premissions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V 位于org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:136) 访问org.openqa.selenium.firefox.GeckoDriverService.access$000(GeckoDriverService.java:41) 位于org.openqa.selenium.firefox.GeckoDriverService$Builder.usingFirefoxBinary(GeckoDriverService.java:108) 位于org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:204) 位于org.openqa.selenium.firefox.FirefoxDriver(FirefoxDriver.java:108) 位于org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:104)
在register_prctc.gmail.main(gmail.java:15)

这里是您问题的解决方案:

  • 要使用Selenium 3.4.0、geckodriver v0.16.1和最新的Mozilla Firefox 53.x,您需要在代码中将geckodriver的绝对路径设置为:
    System.setProperty(“webdriver.gecko.driver”,“C:\\your\u dir\\geckodriver.exe”)
  • 根据最佳实践,您不应使用
    Thread.sleep(6000)
    ,而应使用
    隐式wait
    显式wait

  • 您使用的xpath
    /[@id='gbw']/div/div/div[1]/div[1]/a
    没有标识任何唯一的元素。要查找元素
    Gmail
    链接,您可以使用
    linkText
    定位器:

    Expected [object Undefined] undefined to be a string, 
    The code I am using is following:                 
    System.setProperty("webdriver.gecko.driver","E:\\Software\\geckodriver-
    v0.16.1-win64\\geckodriver.exe");
    WebDriver wd= new FirefoxDriver();
    wd.get("https://www.google.co.in/");
    //wd.findElement(By.xpath(".//*
    [@id='gbw']/div/div/div[1]/div[1]/a")).click();
    wd.findElement(By.linkText("Gmail")).click();
    WebElement e1= wd.findElement(By.xpath("//input[@id='identifierId']"));
    e1.sendKeys("abc@gmail.com");
    wd.findElement(By.xpath("//div[@id='identifierNext']/content/span[text()='Ne
    xt']")).click();
    
  • 要将文本发送到
    电子邮件或电话
    字段,请提供一个唯一的
    xpath
    ,如下所示:

    wd.findElement(By.linkText("Gmail")).click();
    
  • 单击
    Next
    按钮的xpath对我来说似乎很脆弱,您可以将其更改为:
    wd.findElement(By.xpath(“//div[@id='identifierNext']]/content/span[text()='Next'])。单击()

  • 以下是您自己的代码的工作集,其中包含一些简单的调整:

    WebElement e1= wd.findElement(By.xpath("//input[@id='identifierId']"));
    

  • 如果回答了您的问题,请告诉我。

    以下是您问题的解决方案:

  • 要使用Selenium 3.4.0、geckodriver v0.16.1和最新的Mozilla Firefox 53.x,您需要在代码中将geckodriver的绝对路径设置为:
    System.setProperty(“webdriver.gecko.driver”,“C:\\your\u dir\\geckodriver.exe”)
  • 根据最佳实践,您不应使用
    Thread.sleep(6000)
    ,而应使用
    隐式wait
    显式wait

  • 您使用的xpath
    /[@id='gbw']/div/div/div[1]/div[1]/a
    没有标识任何唯一的元素。要查找元素
    Gmail
    链接,您可以使用
    linkText
    定位器:

    Expected [object Undefined] undefined to be a string, 
    The code I am using is following:                 
    System.setProperty("webdriver.gecko.driver","E:\\Software\\geckodriver-
    v0.16.1-win64\\geckodriver.exe");
    WebDriver wd= new FirefoxDriver();
    wd.get("https://www.google.co.in/");
    //wd.findElement(By.xpath(".//*
    [@id='gbw']/div/div/div[1]/div[1]/a")).click();
    wd.findElement(By.linkText("Gmail")).click();
    WebElement e1= wd.findElement(By.xpath("//input[@id='identifierId']"));
    e1.sendKeys("abc@gmail.com");
    wd.findElement(By.xpath("//div[@id='identifierNext']/content/span[text()='Ne
    xt']")).click();
    
  • 要将文本发送到
    电子邮件或电话
    字段,请提供一个唯一的
    xpath
    ,如下所示:

    wd.findElement(By.linkText("Gmail")).click();
    
  • 单击
    Next
    按钮的xpath对我来说似乎很脆弱,您可以将其更改为:
    wd.findElement(By.xpath(“//div[@id='identifierNext']]/content/span[text()='Next'])。单击()

  • 以下是您自己的代码的工作集,其中包含一些简单的调整:

    WebElement e1= wd.findElement(By.xpath("//input[@id='identifierId']"));
    

  • 如果这回答了您的问题,请告诉我。

    删除Selenium-java-2.53.1.jar文件并更新所有jar


    删除Selenium-java-2.53.1.jar文件并更新所有jar


    这是gecodriver的一个持续问题,通过selenium 3.3降低到v0.15。1@AbhijitDatta你可以尝试将Selenium升级到3.4.0,geckodriver升级到v0.16.1,Mozilla Firefox升级到53.x,并尝试执行。让我知道情况。感谢这是gecodriver的一个持续问题,通过selenium 3.3降级至v0.15。1@AbhijitDatta你可以尝试将Selenium升级到3.4.0,geckodriver升级到v0.16.1,Mozilla Firefox升级到53.x,并尝试执行。让我知道情况。感谢遇到了另一个问题。-线程“main”java.lang.NoSuchMethodError中的异常:com.google.common.base.premissions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V----****这个问题的所有解决方案都在番石榴中提供,但我不使用它。。你能解决这个问题吗???@abhijitdatata好,你不需要番石榴,您能更新您当前的代码块和问题区域中的当前错误堆栈跟踪,以便我解释问题所在吗​ 发生感谢问题部分中更新的代码和错误日志。感谢您的帮助。@abhijitdata请执行以下操作:1。将geckodriver复制到方便的位置,最好是在“C:\\some\u文件夹”中。2.更改代码中的路径。3.完全清除Mozilla Firefox浏览器缓存和历史记录。4.如果可能的话,运行CCleaner清除电脑中的所有腐烂的东西。重新启动你的电脑。删除不需要的代码。7.执行你的代码。8.让我知道情况。感谢遇到了另一个问题。-线程“main”java.lang.NoSuchMethodError中的异常:com.google.common.base.premissions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V----****这个问题的所有解决方案都在番石榴中提供,但我不使用它。。你能解决这个问题吗???@abhijitdatata好,你不需要番石榴,您能更新您当前的代码块和问题区域中的当前错误堆栈跟踪,以便我解释问题所在吗​ 发生感谢问题部分中更新的代码和错误日志。感谢您的帮助。@abhijitdata请执行以下操作:1。将geckodriver复制到方便的位置,最好是在“C:\\some\u文件夹”中。2.更改代码中的路径。3.完全清除Mozilla Firefox浏览器缓存和历史记录。4.如果可能的话,运行CCleaner清除电脑中的所有腐烂的东西。重新启动你的电脑。删除不需要的代码。7.执行你的代码。8.让我知道情况。谢谢