#Unable to get number of stars for hotel booking test case in southwest.com
Meta -
OS:
Windows 10
Selenium Version:
2.53.0
Browser:
Chrome
Browser Version:
51.0.2704.103 (64-bit)
Expected Behavior - Expected the number of stars (webelements ) to be identified by the use of size() method
Actual Behavior - Incorrect number of stars are being returned by using size() method
Steps to reproduce -
/Here is the script which I used and attached the output file as well. Expected the number of visible stars to be counted and put into the output file. But, incorrect value, 36 is printed in the o/p file.Kindly check my code and suggest me a solution/
public class CopyOfSouthWestAppTest {
WebDriver oBrw;
private int iEachHotelStarRating;
private int iHotelStarLT4;
@Before public void openApplication(){ System.setProperty("webdriver.chrome.driver","C:\User\IE_GC_Updates\chromedriver.exe"); oBrw = new ChromeDriver(); oBrw.manage().window().maximize(); oBrw.get("https://www.southwest.com/");
}
@Test public void hotelSearch(){
WebDriverWait wait = new WebDriverWait(oBrw, 5);
wait.until(ExpectedConditions.visibilityOf(oBrw.findElement(By.id("booking-form--hotel-tab"))));
oBrw.findElement(By.id("booking-form--hotel-tab")).click();
oBrw.findElement(By.id("hotel-city-destination")).clear();
oBrw.findElement(By.id("hotel-city-destination")).sendKeys("Chelsea");
// SCRIPTING USING CHECKIN AND CHECKOUT ICONS
oBrw.findElement(By.xpath("//a[contains(@class,'check-in-icon')]")).click();
oBrw.findElement(By.id("calendar-july-6")).click();
oBrw.findElement(By.xpath("//a[contains(@class,'check-out-icon')]")).click();
oBrw.findElement(By.id("calendar-july-9")).click();
oBrw.findElement(By.xpath("//form[contains(@id,'booking-form--hotel-panel')]//button[@type='submit']")).click();
}
@After public void hotelSerchResVerify() throws Exception{
iHotelStarLT4 = 0;
iEachHotelStarRating = 0;
List<WebElement> uiHotelNames = oBrw.findElements(By.xpath("//li[@class='hotel_description_outer_container']//span[@class='hotelName']"));
List<WebElement> uiHotelRatings = oBrw.findElements(By.xpath("//span[@class='hotelName']/ancestor::li[@class='hotel_description_outer_container']/child::div/div[2]/div[3]/div/span[contains(@id,'hotelRating')]"));
File oResultsFile = new File("C:/User/Scripts_OP_results/TS1_Results.txt");
PrintWriter oUpdatefile = new PrintWriter(oResultsFile);
for (WebElement uiEachHotel:uiHotelNames){
oUpdatefile.println(uiEachHotel.getText()+"\r\n");
}
for (WebElement uiHotelRatingEach:uiHotelRatings){
List<WebElement> uiNumOfStars = uiHotelRatingEach.findElements(By.xpath("//span[@class='hotelName']/ancestor::li[@class='hotel_description_outer_container']/child::div/div[2]/div[3]/div/span/span[contains(@class,'star_rating_yellow')]"));
iEachHotelStarRating=uiNumOfStars.size();
oUpdatefile.println(iEachHotelStarRating+"\r\n");
if (iEachHotelStarRating > 0 )
if (iEachHotelStarRating < 4 )
iHotelStarLT4++;
}
oUpdatefile.println("Number of hotels with less than 4 stars is equal to: " + iHotelStarLT4);
oUpdatefile.flush();
oUpdatefile.close();
}
}
This is a question rather than an issue. Please send questions to the selenium user group
For issues please provide a concise reproducible test case and describe what results you are seeing and what results you expect.
See CONTRIBUTING.md