XPath选择开始日期和出发日期在booking.com上不起作用。

huangapple go评论77阅读模式
英文:

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();
  • 浏览器截图:

XPath选择开始日期和出发日期在booking.com上不起作用。

英文:

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:

XPath选择开始日期和出发日期在booking.com上不起作用。

huangapple
  • 本文由 发表于 2020年9月15日 21:14:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63902641.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定