Unable to click button "Choose a room" from given url
Could you help me click on "Choose a room" button in below link
url = https://vacation.hotwire.com/Los-Angeles-Hotels-Viceroy-Santa-Monica.h889909.Hotel-Information?chkin=6/30/2019&chkout=7/20/2019&rm1=a2&misId=47e9dda6-6dc4-464b-8fa9-98a7cf5c9dae&sort=recommended&hwrqCacheKey=6b0a830b-39d3-41eb-b3a4-78c2461ac908HWRQ1561875471493&cancellable=false®ionId=178280&vip=false&c=383ce762-5d67-4723-84a7-38ca4fbd6f14&packageType=fh&exp_dp=7951.48&exp_ts=1561875472865&exp_curr=USD&swpToggleOn=false&inttkn=MMXNx4WhAAxLpOw4
import static org.testng.Assert.assertEquals;
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test;
public class HomePage {
WebDriver driver; @BeforeMethod public void setup(){ String value="C:\\Users\\mubeen\\Desktop\\seleniumjars3.8.1\\drivers\\geckodriver.exe"; System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "null"); System.setProperty("webdriver.gecko.driver", value); driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get("http://hotwire.com"); } /* @Test(priority=1) public void getTitle(){ String expectedtitle = "Cheap Hotels, Cars, & Flights | Last Minute Travel Deals | Hotwire"; String title = driver.getTitle(); Assert.assertEquals(expectedtitle, title); } */ @Test public void homePage() throws InterruptedException, ParseException{ System.out.println("homepage"); driver.findElement(By.xpath("//div[text()='Bundles']")).click(); //int frames= driver.findElements(By.tagName("iframe")).size(); //System.out.println(frames); driver.findElement(By.xpath("//input[@id='farefinder-package-origin-location-input']")).sendKeys("SFO"); driver.findElement(By.xpath("//input[@id='farefinder-package-origin-location-input']")).sendKeys(Keys.TAB);
// driver.findElement(By.xpath("//*[@id='typeahead-955-6718']/li[1]")).click(); //Select drop = new Select(driver.findElement(By.xpath("//*[@id='typeahead-955-6718']"))); //drop.selectByIndex(1); Thread.sleep(1000); driver.findElement(By.xpath("//input[@id='farefinder-package-destination-location-input']")).sendKeys("LAX"); driver.findElement(By.xpath("//input[@id='farefinder-package-destination-location-input']")).sendKeys(Keys.TAB); Thread.sleep(2000); Date dt = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(dt); calendar.add(Calendar.DATE, 1); dt = calendar.getTime(); String todaysDate = new SimpleDateFormat("MM/dd/yyyy").format(dt); todaysDate.equals(dt);
//enter tomorrow's date in the Pause field WebElement tomDate = driver.findElement(By.xpath("//*[@id='farefinder-package-startdate-input']")); tomDate.clear(); tomDate.sendKeys(todaysDate); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); Calendar c = Calendar.getInstance(); c.setTime(sdf.parse(todaysDate)); //Number of Days to add c.add(Calendar.DAY_OF_MONTH, 20); //Date after adding the days to the given date String newDate = sdf.format(c.getTime()); WebElement returnDate = driver.findElement(By.xpath("//*[@id='farefinder-package-enddate-input']")); returnDate.clear(); returnDate.sendKeys(newDate);
driver.findElement(By.xpath("//*[@id='farefinder-package-search-button']")).submit();
List<WebElement> e = driver.findElements(By.xpath("//a[@class='flex-link']")); System.out.println(e.size()); e.get(0).click(); Thread.sleep(2000); Set<String> WinIds = driver.getWindowHandles(); Iterator<String> it = WinIds.iterator();
System.out.println(WinIds.size());
String firstpop = it.next(); String secondpop = it.next(); System.out.println(firstpop); System.out.println(secondpop);
driver.switchTo().window(secondpop); driver.switchTo().defaultContent(); //System.out.println(WinIds.size()); //driver.findElement(By.xpath("//button[@id='mock-book-button']")).submit(); //WebDriverWait wait = new WebDriverWait(driver, 20); //wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='mock-book-button']"))).click();
/* WebElement element = driver.findElement(By.xpath("//button[@id='mock-book-button']")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element); */ Thread.sleep(3000); int total1 = driver.findElements(By.tagName("iframe")).size(); System.out.println("total frame1"+"--"+total1); driver.switchTo().frame(0); /* WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='mock-book-button']"))).click(); */ driver.findElement(By.xpath("//button[@id='mock-book-button']")).submit();
} /* @AfterMethod public void tearDown(){ driver.quit(); } */
[RemoteTestNG] detected TestNG version 6.14.2 Jun 29, 2019 11:32:03 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C homepage 5 2 4294967297 4294967358 total frame1--1 FAILED: homePage org.openqa.selenium.NoSuchElementException: Unable to locate element: //button[@id='mock-book-button'] For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z' System info: host: 'MUBEEN', ip: '169.254.144.87', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 58.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 69172, moz:profile: C:\Users\mubeen\AppData\Loc..., moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}} Session ID: c7fa7b74-6c80-4001-aea5-6a8364600442 *** Element info: {Using=xpath, value=//button[@id='mock-book-button']} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:319) at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:421) at org.openqa.selenium.By$ByXPath.findElement(By.java:361) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:311) at HomePage.homePage(HomePage.java:143) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
=============================================== Default test Tests run: 1, Failures: 1, Skips: 0 ===============================================
=============================================== Default suite Total tests run: 1, Failures: 1, Skips: 0 ===============================================
The error is at HomePage.java line number 143.
Also, the code is not able to locate the XPath //button[@id='mock-book-button'] on the page.
We offer online selenium and UFT/QTP training. The course is very comprehensive and covers every aspect of automation testing with UFT/QTP and selenium. All types of frameworks are covered in depth - data driven framework, hybrid framework, page object model with a live project
© 2020 Whizdom Trainings. All rights Reserved - Powered by Whizdom Trainings