PhantomJS提交按钮未单击-在Selenium中工作

PhantomJS提交按钮未单击-在Selenium中工作,phantomjs,Phantomjs,我很难使用submit按钮,当在Selenium works中运行相同的代码时,它在phantomJS中没有被单击。 有人有什么建议吗(用Java) 公务舱航班 { 网络驱动程序; File File=新文件(“C:/Program Files/phantomjs-2.1.1-windows/bin/phantomjs.exe”); @试验 public void homePageFlightDetails()引发异常 { //设置重影驱动程序 setProperty(“phantomjs.bi

我很难使用submit按钮,当在Selenium works中运行相同的代码时,它在phantomJS中没有被单击。 有人有什么建议吗(用Java)

公务舱航班

{ 网络驱动程序; File File=新文件(“C:/Program Files/phantomjs-2.1.1-windows/bin/phantomjs.exe”); @试验 public void homePageFlightDetails()引发异常 { //设置重影驱动程序 setProperty(“phantomjs.binary.path”,file.getAbsolutePath())

//***************************************************
//FIREFOX UI调试-将UI调试的调试设置为True
布尔调试=假;
如果(调试)
{
驱动程序=新的FirefoxDriver();
driver.manage().window().maximize();
}
其他的
{
driver=新的PhantomJSDriver();
//将日志记录设置为Severe Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.Severe);
}
//***************************************************
//提交主页并获取标题
驱动程序。获取(“http://www.aa.com");
字符串pageTitle=driver.getTitle();
System.out.println(“当前页面标题为“+pageTitle”);
//查找“始发机场”字段
WebElement originAirport=driver.findElement(By.id(“reservationFlightSearchForm.originAirport”);
//清除所有现有文本并输入原始机场
原始机场。清除();
originAirport.sendKeys(“PHX”);
//查找目的地机场字段
WebElement destAirport=driver.findElement(By.id(“reservationFlightSearchForm.destinationAirport”);
清除机场();
destAirport.sendKeys(“LAS”);
//查找出发日期字段
WebElement depDate=driver.findElement(By.id(“aa leavingOn”);
depDate.clear();
发布日期:sendKeys(“2016年8月20日”);
//查找返回日期字段
WebElement retDate=driver.findElement(By.id(“aa returningFrom”);
retDate.clear();
返回日期。发送密钥(“2016年8月24日”);
//查找“向上搜索”按钮
//WebElement searchButton=driver.findElement(By.id(“flightSearchForm.button.reSubmit”);
//driver.findElement(By.id(“flightSearchForm.button.reSubmit”))。单击();
//WebElement searchButton=driver.findElement(By.xpath(“/*[@value='Search'][@type='submit']);
//phantomjs调试-验证按钮是否已找到
boolean buttonText=driver.findElement(By.xpath(“/*[@value='Search'][@type='submit']])).isDisplayed();
System.out.println(“buttonText Boolean is=“+buttonText”);
//单击搜索按钮
//findElement(By.xpath(“//*[@value='Search'][@type='submit'])).sendKeys(key.RETURN);
//***********这在硒中起作用
driver.findElement(By.xpath(“/*[@value='Search'][@type='submit'])。单击();
//等待“选择航班”页面出现
整数计数=1;
做
if(driver.getTitle()包含(“选择航班”))
{
打破
}
其他的
{
System.out.println(“do循环迭代”+count+”标题=“+driver.getTitle());
睡眠(1000);
计数++;
}
而(计数<30);
System.out.println(“搜索后,当前页面标题为=“+driver.getTitle()”);
Assert.assertTrue(driver.getTitle()包含(“选择航班”);
driver.quit();
}

通过Jmeter(with)使用phantomjs时,我遇到了类似的问题

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


我能想到的唯一解决办法是调用函数(button onclick函数),尽管这不是我的首选。

通过Jmeter(with)使用phantomjs时,我遇到了类似的问题

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

我能想到的唯一解决办法是调用函数(ButtonOnClick函数),尽管这不是我的偏好

       //***************************************************
       // 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();
   }