【问题标题】:PhantomJS submit button not clicked - works in Selenium未单击 PhantomJS 提交按钮 - 在 Selenium 中工作
【发布时间】:2016-11-20 12:03:13
【问题描述】:

我很难使用提交按钮,当在 Selenium 中运行时,它没有在 phantomJS 中单击相同的代码。 有没有人有任何建议(在 Java 中)?

公开课 BookFlight

{ WebDriver 驱动程序; File file = new File("C:/Program Files/phantomjs-2.1.1-windows/bin/phantomjs.exe"); @测试 public void homePageFlightDetails() 抛出异常 { //设置GhostDriver System.setProperty("phantomjs.binary.path", file.getAbsolutePath());

       //***************************************************
       // FIREFOX UI DEBUG - Set debug to True for UI debug
       boolean debug=false;
       if (debug)
          {
          driver= new  FirefoxDriver();
          driver.manage().window().maximize();
          }
       else
       {
          driver=new PhantomJSDriver();
        //Set logging to Severe            Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.SEVERE);
       }

       //***************************************************
        //Submit Home page and get the title
        driver.get("http://www.aa.com");
        String pageTitle = driver.getTitle();
        System.out.println("The Current page title is  "+pageTitle); 

       //Find the origin airport field
       WebElement originAirport=driver.findElement(By.id("reservationFlightSearchForm.originAirport" ));
       //Clear any existing text and enter the origin airport
       originAirport.clear();
       originAirport.sendKeys("PHX");

       //Find the destination airport field
       WebElement destAirport=driver.findElement(By.id("reservationFlightSearchForm.destinationAirport" ));

       destAirport.clear();
       destAirport.sendKeys("LAS");

       //Find the depart date field
       WebElement depDate = driver.findElement(By.id("aa-leavingOn"));
       depDate.clear();
       depDate.sendKeys("08/20/2016");

       //Find the return date field
       WebElement retDate = driver.findElement(By.id("aa-returningFrom"));
       retDate.clear();
       retDate.sendKeys("08/24/2016");

       //Find the Search up button
       // WebElement searchButton = driver.findElement(By.id("flightSearchForm.button.reSubmit"));
       // driver.findElement(By.id("flightSearchForm.button.reSubmit")).click();
      // WebElement searchButton = driver.findElement(By.xpath("//*[@value='Search'][@type='submit']"));

       //phantomjs debug  - Verify the button has been found
       boolean buttonText = driver.findElement(By.xpath("//*[@value='Search'][@type='submit']")).isDisplayed();
       System.out.println("buttonText Boolean is = "+buttonText);

       //Click the Search button         
       //driver.findElement(By.xpath("//*[@value='Search'][@type='submit']")).sendKeys(Keys.RETURN);

              //***********  This works in Selenium *********** 
       driver.findElement(By.xpath("//*[@value='Search'][@type='submit']")).click();
       // Wait for the Choose Flights page to appear
       int count = 1;
       do
          if (driver.getTitle().contains("Choose flights"))
          {
                 break;
          }
          else
          {
             System.out.println("do loop iteration "+count+ " the title = "+ driver.getTitle());
             Thread.sleep(1000);
                    count++;
          }
       while (count < 30);            
       System.out.println("After search the current page title is  = "+ driver.getTitle());
       Assert.assertTrue(driver.getTitle().contains("Choose flights"));
       driver.quit();
   }

【问题讨论】:

    标签: phantomjs


    【解决方案1】:

    我在通过 Jmeter 使用 phantomjs 时遇到了类似的问题(使用 WebDriver Sampler)。

    我可以看到页面上存在一个模式,它覆盖了我需要与之交互的字段。我可以添加断言来验证字段和按钮是否存在并捕获它们的值,只是不能点击按钮。

    我能想到的唯一解决方法是调用该函数(按钮 onclick 函数),尽管不是我的偏好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-03
      • 2020-01-15
      • 2023-04-10
      相关资源
      最近更新 更多