我试图使用Selenium自动化Make My Trip网站。这些是我采取的步骤:
它说,找不到元素。
我尝试过以下方法:
1.试图通过id
找到元素
2.试图通过xpath
//div[@class='feedback-form-container']//form[@id='feedbackForm']//input[@id='field_name_NAME']"
代码:
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseURL = "http://www.google.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void makeMyTriptest() throws Exception {
System.out.println("Entered this loop");
driver.get(baseURL + "/?gws_rd=ssl");
driver.findElement(By.id("lst-ib")).sendKeys("makemytrip");
System.out.println("send keys successful");
driver.findElement(By.linkText("Flights - MakeMyTrip")).click();
driver.findElement(By.id("country_links")).click();
driver.findElement(By.xpath("//*[@id='country_dropdown']//p//a[@href='http://us.makemytrip.com/']")).click();
driver.findElement(By.xpath("//div[@id='webklipper-publisher-widget-container-content-expand-collapse']")).click();
//entering feedback details
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//driver.findElement(By.id("field_name_NAME")).sendKeys("SubbaRao");
driver.findElement(By.xpath("//div[@class='feedback-form-container']//form[@id='feedbackForm']//input[@id='field_name_NAME']")).sendKeys("SubbaRao");
//driver.findElement(By.id("field_email_EMAIL")).sendKeys("test@test.com");
}
答案 0 :(得分:0)
反馈表单位于iframe内。你必须切换到它的上下文:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
//WebElement iFrame = driver.findElement(By.xpath("//*[id='print_ticket_overlayiframe']"));
driver.switchTo().defaultContent();
driver.switchTo().frame("webklipper-publisher-widget-container-frame");
//driver.findElement(By.id("field_name_NAME")).sendKeys("SubbaRao");
driver.findElement(By.xpath("//*[@id='field_name_NAME']")).sendKeys("SubbaRao");
现在,当您在iframe中时,搜索输入
适合我。