Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在尝试测试“的新特性”;yatra.com“;通过selenium,但不获取代码如何单击book ticket?_Selenium_Selenium Webdriver_Selenium Ide_Selenium Rc - Fatal编程技术网

我正在尝试测试“的新特性”;yatra.com“;通过selenium,但不获取代码如何单击book ticket?

我正在尝试测试“的新特性”;yatra.com“;通过selenium,但不获取代码如何单击book ticket?,selenium,selenium-webdriver,selenium-ide,selenium-rc,Selenium,Selenium Webdriver,Selenium Ide,Selenium Rc,导入org.openqa.selenium.By; 导入org.openqa.selenium.firefox.FirefoxDriver 公共级雅特拉{ 公共静态void main(字符串[]args){ }}类名新建蓝色按钮fr book button js bookNow您用于book Now的按钮只有在单击或悬停在该按钮上后才可用。因此,Selenium无法识别定位器 而是编写一些相关的xpath,如下所示。它应该会起作用。这一个用于第一个按钮,第二个用于第三个按钮等,更改第一个div的

导入org.openqa.selenium.By; 导入org.openqa.selenium.firefox.FirefoxDriver

公共级雅特拉{ 公共静态void main(字符串[]args){


}}类名
新建蓝色按钮fr book button js bookNow
您用于
book Now
的按钮只有在单击或悬停在该按钮上后才可用。因此,Selenium无法识别定位器

而是编写一些相关的xpath,如下所示。它应该会起作用。这一个用于第一个按钮,第二个用于第三个按钮等,更改第一个div的索引编号(
div[7]
div[8]
,其中be用于第二个按钮,
div[9]
中be用于第三个按钮等)


下面为我工作,请检查并回复

driver.get("http://www.yatra.com");
driver.findElement(By.className("iconBeta")).click();
driver.findElement(By.xpath(".//input[contains(@id,'nlp_query')]")).sendKeys("go air evening flight from Mumbai to Chennai coming Sunday");
        driver.findElement(By.xpath(".//input[contains(@id,'nlp_submit')]")).click();
    try
    {
        Thread.sleep(5000);
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }

    WebElement we = driver.findElement(By.xpath("(//div[@class='js-flightRow js-flightItem ng-scope']//div[@class='my-res-info full']//span[contains(text(),'Book Now')])[last()]"));

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click()", we);

请分享您收到的错误。您好,先生,谢谢您的回复,我对automachine world“driver.findelelement(By.xpath(“./*[@id='BOMMAAG8303G820160911']/div[1]/ul/li[5]/div/p[2]”)非常陌生。单击();“我通过使用xpath添加了这一行,但仍然面临相同的错误,您能解释我的错误并帮助我现在如何进入这本书吗?”?
//div[7]/article/div[1]/ul/li[5]/div/p[2]
driver.get("http://www.yatra.com");
driver.findElement(By.className("iconBeta")).click();
driver.findElement(By.xpath(".//input[contains(@id,'nlp_query')]")).sendKeys("go air evening flight from Mumbai to Chennai coming Sunday");
        driver.findElement(By.xpath(".//input[contains(@id,'nlp_submit')]")).click();
    try
    {
        Thread.sleep(5000);
    }
    catch (InterruptedException e)
    {
        e.printStackTrace();
    }

    WebElement we = driver.findElement(By.xpath("(//div[@class='js-flightRow js-flightItem ng-scope']//div[@class='my-res-info full']//span[contains(text(),'Book Now')])[last()]"));

    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("arguments[0].click()", we);