英文:
xpath to select start-date and departure-date not working for booking.com
问题
driver.findElement(By.xpath("//input[@id='ss']")).sendKeys("London");
Thread.sleep(5000);
driver.findElement(By.xpath("//span[contains(.,'LondonGreater London, United Kingdom')]")).click();
Thread.sleep(9000);
driver.findElement(By.xpath("//div[@class='xp__dates-inner']")).click();
Actions startdate = new Actions(driver);
WebElement mainMenu = driver.findElement(By.xpath(".//div[@class= 'bui-calendar']//table[@class='bui-calendar__dates']//tr[@class='bui-calendar__row']//td[@data-date='2020-09-27']"));
startdate.moveToElement(mainMenu).click().build().perform();
Thread.sleep(8000);
Actions enddate = new Actions(driver);
WebElement mainMenu1 = driver.findElement(By.xpath(".//div[@class= 'bui-calendar']//table[@class='bui-calendar__dates']//tr[@class='bui-calendar__row']//td[@data-date='2020-09-28']"));
enddate.moveToElement(mainMenu1).click().build().perform();
driver.findElement(By.xpath(".//div[@class='sb-searchbox-submit-col -submit-button ']")).click();
Thread.sleep(6000);
英文:
To select start-date and departure-date for https://www.booking.com/ my code is not giving error but date is not selected.Tried with the actions class but no use.
link:- booking.com
driver.findElement(By.xpath("//input[@id='ss']")).sendKeys("London");
Thread.sleep(5000);
driver.findElement(By.xpath("//span[contains(.,'LondonGreater London, United Kingdom')]")).click();
Thread.sleep(9000);
driver.findElement(By.xpath("//div[@class='xp__dates-inner']")).click();
Actions startdate = new Actions(driver);
WebElement mainMenu = driver.findElement(By.xpath(".//div[@class= 'bui-calendar']//table[@class='bui-calendar__dates']//tr[@class='bui-calendar__row']//td[@data-date='2020-09-27']"));
startdate.moveToElement(mainMenu).click().build().perform();
Thread.sleep(8000);
Actions enddate = new Actions(driver);
WebElement mainMenu1 = driver.findElement(By.xpath(".//div[@class= 'bui-calendar']//table[@class='bui-calendar__dates']//tr[@class='bui-calendar__row']//td[@data-date='2020-09-28']"));
enddate.moveToElement(mainMenu1).click().build().perform();
driver.findElement(By.xpath(".//div[@class='sb-searchbox-submit-col -submit-button ']")).click();
Thread.sleep(6000);
答案1
得分: 2
设置入住日期为周二,9月29日
,退房日期为周三,9月30日
,在 https://www.booking.com/ 上,您需要使用WebDriverWait等待 elementToBeClickable()
并且您可以使用以下基于[tag:xpath]的定位策略:
driver.get("https://www.booking.com/index.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaGyIAQGYAQm4AQfIAQzYAQHoAQGIAgGoAgO4ArregvsFwAIB0gIkYWZiOGRhYmItNzgxOS00YWFjLWE2YTgtOWQwNTNkNDExYjBl2AIF4AIB;keep_landing=1&sb_price_type=total&");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@class, 'xp__dates__checkin')]//span[contains(@class, 'calendar-restructure-sb')]"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='xp-calendar']//table[@class='bui-calendar__dates']//tr//td[@data-date='2020-09-29']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='xp-calendar']//table[@class='bui-calendar__dates']//tr//td[@data-date='2020-09-30']"))).click();
- 浏览器截图:
英文:
To set Check-in date as Tue 29 Sept
and Check-out date as Wed 30 Sept
on https://www.booking.com/ you need to induce WebDriverWait for the elementToBeClickable()
and you can use the following [tag:xpath] based Locator Strategies:
driver.get("https://www.booking.com/index.en-gb.html?label=gen173nr-1BCAEoggI46AdIM1gEaGyIAQGYAQm4AQfIAQzYAQHoAQGIAgGoAgO4ArregvsFwAIB0gIkYWZiOGRhYmItNzgxOS00YWFjLWE2YTgtOWQwNTNkNDExYjBl2AIF4AIB;keep_landing=1&sb_price_type=total&");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@class, 'xp__dates__checkin')]//span[contains(@class, 'calendar-restructure-sb')]"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='xp-calendar']//table[@class='bui-calendar__dates']//tr//td[@data-date='2020-09-29']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='xp-calendar']//table[@class='bui-calendar__dates']//tr//td[@data-date='2020-09-30']"))).click();
- Browser Snapshots:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论