选择酒店并提供信息时。选择下拉菜单无法选择标题。我使用了selectByVisibleText,index和value,但它还没有选择标题。 (网站链接:https://www.trivago.in/?aDateRange[arr]=2018-06-16&aDateRange[dep]=2018-06-20&aPriceRange[to]=15145&aPriceRange[from]=500&iPathId=84780&aGeoCode[lat]=19.075983&aGeoCode[lng]=72.877655&iGeoDistanceItem=0&aCategoryRange=0%2C1%2C2%2C3%2C4%2C5&aOverallLiking=1%2C2%2C3%2C4%2C5&sOrderBy=relevance%20desc&bTopDealsOnly=false&iRoomType=1&cpt=8478003&iIncludeAll=0&iViewType=0&bIsSeoPage=false&bIsSitemap=false&)
好的,所以手动我会告诉你上面的代码做了什么
1.在这里搜索孟买并选择日期为6月16日至2018年6月20日
driver.findElement(By.id("horus-querytext")).sendKeys("Mumbai");
driver.findElement(By.xpath("//button[@ref='searchButton']")).click();
Thread.sleep(5000);
driver.findElement(By.className("cal-btn-next")).click();
driver.findElement(By.className("cal-btn-next")).click();
//Selecting June 16 2018
driver.findElement(By.xpath("//td//time[@datetime='2018-06-16']")).click();
//Selecting June 20 2018
driver.findElement(By.xpath("//td//time[@datetime='2018-06-20']")).click();
2.然后我使用鼠标操作选择我的房间为"双人间"
Actions builder = new Actions(driver);
WebElement doubleRoom = driver.findElement(By.xpath(".//*[@id='js-fullscreen-hero']/div/form/div[2]/div/div/ul/li[2]/button"));
Action pointOver = builder.moveToElement(doubleRoom).click().build();
pointOver.perform();
Thread.sleep(10000);
3.在这里我选择酒店并查看酒店的照片
//Selecting a Hotel
driver.findElement(By.xpath(".//*[@id='js_item_3486926']/div[1]/div[3]/div/div[1]/h3")).click();
//Previewing Photos
driver.findElement(By.xpath("//li[@class='tabs__item tabs__item--active']//button[@class='tabs__label']")).click();
driver.findElement(By.cssSelector(".gal-mob__arrow.gal-mob__arrow--trailing")).click();
driver.findElement(By.cssSelector(".gal-mob__arrow.gal-mob__arrow--trailing")).click();
//closing the hotel window
driver.findElement(By.cssSelector(".btn.btn--small.btn--tertiary.slo-btn--close")).click();
4.在这段代码中,我选择了我的酒店
driver.findElement(By.xpath(".//*[@id='js_item_3486926']/div[1]/div[3]/section[2]/div/button[2]")).click();
Thread.sleep(10000);
5.一旦我选择了我的酒店,它将带我到另一个窗口预订。
String parentWindow = driver.getWindowHandle();
System.out.println("Parent Window ID is : " + parentWindow);
int count = allWindow.size();
System.out.println("Total Window : " + count);
for(String child:allWindow)
{
if(!parentWindow.equalsIgnoreCase(child))
{
6.在这里打开儿童窗口:
driver.switchTo().window(child);
driver.findElement(By.id("choose-room-disable")).click();
Thread.sleep(3000);
7.点击此处的预订按钮:
//Booking room for two
driver.findElement(By.xpath("//button[@ng-if='!isAppFor.destranet']")).click();
的Thread.sleep(3000);
8.另外一页加载我必须提供详细信息:
//Email & Phone Number
driver.findElement(By.id("additionalContactEmail")).sendKeys("xyz@123.com");
driver.findElement(By.id("additionalContactMobile")).sendKeys("000000000");
9.现在问题所在,这段代码应该选择标题。它并没有这样做,正如我之前所说,我已经使用了selectByVisibleText,index和value,但它仍然没有选择标题。
//Selecting Title
driver.findElement(By.xpath(".//*[@id='paxNum0']/div[2]/div[1]/span/select")).click();
Select dropDwn = new Select(driver.findElement(By.xpath(".//*[@id='paxNum0']/div[2]/div[1]/span/select")));
dropDwn.selectByIndex(1);
Thread.sleep(4000);
//Name
driver.findElement(By.id("travellerf0")).sendKeys("Divya");
driver.findElement(By.id("travellerl0")).sendKeys("Master");
driver.findElement(By.xpath(".//*[@id='traveller-dom']/form/div[3]/button")).click();
Thread.sleep(4000);
driver.close();
}
}
driver.switchTo().window(parentWindow);
答案 0 :(得分:0)
如果您尝试仅运行处理的最后一个部分,请单击dropdown element
,您会看到它正常工作。所以你的问题可能与选择标题'无关。一部分。
以下代码工作得很好,我可以看到正在选择的下拉元素:
WebDriver driver = new ChromeDriver();
driver.get("https://hotel.yatra.com/hotel-checkout/dom/hotel/review?ci=YTVG&tenant=TRIVAGO&checkInDate=16/06/2018&checkOutDate=20/06/2018&city.name=Mumbai&city.code=Mumbai&hotelId=00000538&rooms[0].noOfChildren=0&rooms[0].id=0&rooms[0].noOfAdults=2&_rn=46u&roomTypeId=0000240804&ratePlanId=0000937548&utm_content=dCbfGbk24MQ&excludeHotelTax=false&chpFare=0&searchId=6678a1eb-5000-4db2-a3e7-2ac1ea47a1ef");
Select dropDwn = new Select(driver.findElement(By.xpath(".//*[@id='paxNum0']/div[2]/div[1]/span/select")));
dropDwn.selectByIndex(1);