即使在使用隐式等待之后,Selenium中的超时错误

时间:2018-04-11 09:08:58

标签: java selenium selenium-webdriver

有人可以帮助我解决这个超时错误..而不是使用隐式等待,我不知道为什么它仍然给我超时错误。我是Selenium的新手。这是我的基类:

public class BaseClass {
 public static WebDriver driver;

    @BeforeClass
    public void SetUpDriver (){
        //WebDriver driver;
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\ketaki.naik\\Selenium\\Gecko_new\\geckodriver-v0.17.0-win64\\geckodriver-v0.17.0-win32-1\\geckodriver.exe");

        DesiredCapabilities cap = DesiredCapabilities.firefox();
        driver = new FirefoxDriver(cap);
        String driver_name= "webdriver.gecko.driver";
        String driver_location = "C:\\Users\\ketaki.naik\\Selenium\\Gecko_new\\geckodriver-v0.17.0-win64\\geckodriver-v0.17.0-win32-1\\geckodriver.exe";
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\ketaki.naik\\Selenium\\Gecko_new\\geckodriver-v0.17.0-win64\\geckodriver-v0.17.0-win32-1\\geckodriver.exe");
        System.setProperty(driver_name,driver_location); 
        /*driver = new FirefoxDriver();*/
        //driver.manage().window().maximize();
        driver.get("https://uat-pepsico.base.website");
        //driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.SECONDS);

        }

        @Test
        public void AClickloginToApplication (){
        //driver.manage().timeouts().setScriptTimeout(10000, TimeUnit.SECONDS);

        driver.findElement(By.id("username")).sendKeys("******");
        driver.findElement(By.id("password")).sendKeys("*********");
        driver.findElement(By.id("_submit")).click();

        }

我正在将这个基类扩展到我的MediaTouchPoints类,理想情况下应该打开报告的Excel工作表:

public class MediaTouchPoints extends BaseClass {

    @Test
    public void MediaType1() {

    try{
    //driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
            driver.findElement(By.xpath("//li[@title='reports']/a")).click();
            driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
}
    catch (Exception E)
    {
        System.out.println("Your exception is from MediaType1===" + E);
    }
    }

@Test
public void MediaType2() {
 int this_one = -1;
// System.out.println("I am inside MediaTYpe2");        

 try{
      driver.manage().timeouts().implicitlyWait(50000000, TimeUnit.SECONDS);


         List<WebElement> ReportMenu =driver.findElements(By.xpath("//ul[@class='menu-title menu_level_1 collapse in']//li/a/span"));

            //System.out.println("List from the menu===" + ReportMenu);

            driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);

           for (int i=0;i<ReportMenu.size();i++)
           {

            WebElement element = ReportMenu.get(i);

            String innerhtml= element.getAttribute("innerHTML");
            //System.out.println("Element is===" + element);

            //System.out.println(innerhtml);


           //Thread.sleep(1000);
            if(innerhtml.trim().equalsIgnoreCase(("Media Touch-points")))
            {
                    this_one = i;
                    break;


           }
            System.out.println("I am here..LA LA LA");
            /*else {
                System.out.println("I have not performed IF-----");
            }*/
           }
        }
        catch(Exception E){
            System.out.println("Your exception is from MediaType2 ******====" + E);

        }

        if (this_one > -1)
        {
            try{
                  List<WebElement> ReportMenu =driver.findElements(By.xpath("//ul[@class='menu-title menu_level_1 collapse in']//li/a"));

                   driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

                   WebElement element = ReportMenu.get(this_one);
                   element.click();
                  // driver.findElement(By.xpath("//[@id='budgets_table_wrapper']/tbody/tr[1]/td[7]/a")).click();
                   driver.findElement(By.xpath("//*[@id='budgets_table']/tbody/tr[4]/td[6]/a")).click();
                    driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
                }
                catch(Exception E)
                  {
                    System.out.println("Your exception is from 2nd test====" + E);

                  }

        }

 }

        @Test
        public void MediaType3(){

            //driver.findElement(By.xpath("//*[@id='excel_export']")).click();
            //driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
            driver.findElement(By.xpath("//*[@id='ptp_table_wrapper']/div[1]/a[2]/span")).click();
            driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
        } 


    /*   @Test
       public void SelectProject() throws InterruptedException{

           Thread.sleep(10000);
           driver.findElement(By.xpath("//div[@id='budgets_table_wrapper']/div[2]/div/table/tbody/tr[2]/td[7]/a")).click();
           System.out.println("i want top click on Select button"); */

        @Test(priority=4)
        public void CampaignStatusReport_4() throws AWTException
        {
         try{
       // System.out.println("I am here....");
        //WebDriverWait wait = new WebDriverWait(driver, 3000);
        driver.manage().timeouts().implicitlyWait(1000, TimeUnit.SECONDS);
        //driver.manage().window().maximize();
        /*driver.switchTo().frame("ModelFrametitle");*/
        Robot object=new Robot();

        // Press Enter
        object.keyPress(KeyEvent.VK_ENTER);

        // Release Enter
        object.keyRelease(KeyEvent.VK_ENTER);

        }
        catch(Exception E)
        {
            System.out.println("My Exception is=== " + E);

        }

        }    

      /* @AfterClass
        public void CloseWindow (){
            driver.quit();


        }*/

    } 

以下是错误:

1523434293660   geckodriver INFO    Listening on 127.0.0.1:19624
1523434296927   geckodriver::marionette INFO    Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
Unable to read VR Path Registry from C:\Users\ketaki.naik\AppData\Local\openvr\openvrpaths.vrpath
1523434300402   Marionette  INFO    Enabled via --marionette
Unable to read VR Path Registry from C:\Users\ketaki.naik\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\ketaki.naik\AppData\Local\openvr\openvrpaths.vrpath
Unable to read VR Path Registry from C:\Users\ketaki.naik\AppData\Local\openvr\openvrpaths.vrpath
1523434306760   Marionette  INFO    Listening on port 62931
Unable to read VR Path Registry from C:\Users\ketaki.naik\AppData\Local\openvr\openvrpaths.vrpath
1523434307188   Marionette  WARN    TLS certificate errors will be ignored for this session
Apr 11, 2018 9:11:48 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Apr 11, 2018 9:12:01 AM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown error' (500 expected)
Your exception is from MediaType1===org.openqa.selenium.WebDriverException: timeouts
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ABCLAPTOP23', ip: '172.16.0.165', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ketaki.naik\AppData\Local\Temp\rust_mozprofile.SsTh4gNfMgDB, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, moz:headless=false, platform=ANY, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=true, browserVersion=59.0.2, platformVersion=10.0, moz:processID=15892.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt, moz:webdriverClick=true}]
Session ID: ef372642-2445-43ee-9eac-e210229f397f
Apr 11, 2018 9:12:01 AM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown error' (500 expected)
Your exception is from MediaType2 ******====org.openqa.selenium.WebDriverException: timeouts
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ABCLAPTOP23', ip: '172.16.0.165', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ketaki.naik\AppData\Local\Temp\rust_mozprofile.SsTh4gNfMgDB, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, moz:headless=false, platform=ANY, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=true, browserVersion=59.0.2, platformVersion=10.0, moz:processID=15892.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt, moz:webdriverClick=true}]
Session ID: ef372642-2445-43ee-9eac-e210229f397f
Apr 11, 2018 9:12:01 AM org.openqa.selenium.remote.ErrorCodes toStatus
INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown error' (500 expected)
My Exception is=== org.openqa.selenium.WebDriverException: timeouts
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ABCLAPTOP23', ip: '172.16.0.165', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ketaki.naik\AppData\Local\Temp\rust_mozprofile.SsTh4gNfMgDB, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, moz:headless=false, platform=ANY, moz:accessibilityChecks=false, moz:useNonSpecCompliantPointerOrigin=false, acceptInsecureCerts=true, browserVersion=59.0.2, platformVersion=10.0, moz:processID=15892.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt, moz:webdriverClick=true}]
Session ID: ef372642-2445-43ee-9eac-e210229f397f
PASSED: AClickloginToApplication
PASSED: MediaType1
PASSED: MediaType2
PASSED: CampaignStatusReport_4
FAILED: MediaType3

1 个答案:

答案 0 :(得分:0)

错误说明了一切:

INFO: HTTP Status: '404' -> incorrect JSON status mapping for 'unknown error' (500 expected)
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ABCLAPTOP23', ip: '172.16.0.165', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver

从错误日志中可以清楚地看到:

  • Selenium Client 未被识别为:

    Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
    
  • FirefoxDriver服务器未被识别为:

    Driver info: org.openqa.selenium.firefox.FirefoxDriver
    

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

  • 您的 JDK版 1.8.0_121 ,这很古老。
  • 我们不知道您的 Selenium客户端版本。
  • 我们不知道您的 GeckoDriver 版本。
  • 您的 Firefox 版本不为我们所知。

因此 JDK v8u121 与当前的 Selenium Client v3.11.0 之间存在明显的不匹配。

解决方案

  • JDK 升级到最近的级别JDK 8u162
  • Selenium 升级到当前级别Version 3.11.0
  • GeckoDriver 升级到GeckoDriver v0.20.0级别。
  • Firefox 版本升级至 Firefox v59.0.1 级别。
  • 通过 IDE 清理您的项目工作区仅使用所需的依赖项重建项目
  • 使用CCleaner工具清除执行 Test Suite 之前和之后的所有操作系统杂务。
  • 如果您的基本 Web客户端版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的 Web客户端版本。
  • 进行系统重启
  • 执行@Test
  • 始终在driver.quit()方法中调用tearDown(){}以关闭&amp;正常销毁 WebDriver Web客户端实例。