我正在尝试测试“的新特性”;yatra.com“;通过selenium,但不获取代码如何单击book ticket?
导入org.openqa.selenium.By; 导入org.openqa.selenium.firefox.FirefoxDriver 公共级雅特拉{ 公共静态void main(字符串[]args){我正在尝试测试“的新特性”;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的
}}类名
新建蓝色按钮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);