0

I am trying to Hover over all seats and click on the available seat. But I cannot Break the webelement Loop, once available seat is found. It hover's over some seat, and never clicks on any.

Here's My code ...

List<WebElement> seats = driver.findElements(By.xpath("//div[@style='max-width:695px;']/div[2]/div[2]/table/tbody/tr/td/div"));

            for (WebElement seat : seats) 
        {           
            Actions builder=new Actions(driver);
            builder.moveToElement(seat).build().perform();
            Thread.sleep(9000);
            WebElement available = (WebElement) driver.findElements(By.xpath("//div[@class='popupContent']/div/div/span[2]"));
            if (available.getText() == "(Available)")

            {
                seat.click();
                System.out.println("Seat is available");
                break;
            } else {
                System.out.println("Seat is Not available");

            }
        }

enter image description here

Himadri
  • 150
  • 2
  • 11

1 Answers1

0

Yes Shail016 mentioned in comment you should use equals method to compare two strings but not ==.

Refer below thread to get more clarity on String comparison

Java String.equals versus ==

Try with below code.

List<WebElement> seats = driver.findElements(By.xpath("//div[@style='max-width:695px;']/div[2]/div[2]/table/tbody/tr/td/div"));
        for (WebElement seat : seats) 
        {           
            Actions builder=new Actions(driver);
            builder.moveToElement(seat).build().perform();
            Thread.sleep(9000);
            WebElement available = (WebElement)        driver.findElements(By.xpath("//div[@class='popupContent']/div/div/span[2]"));
            if (available.getText().equals("(Available)"))
            {
                seat.click();
                System.out.println("Seat is available");
                break;
            } else {
                System.out.println("Seat is Not available");

            }
        }
Community
  • 1
  • 1
Santoshsarma
  • 5,627
  • 1
  • 24
  • 39
  • thanks for the suggestion, i made the changes , still it only Hovers and does not click... – Himadri Jun 12 '14 at 11:51
  • 1
    Just try to print available.getText() value after mouse hovering. If it is printing properly/required value ((Available)) for available seats.. it clicks. – Santoshsarma Jun 12 '14 at 11:55
  • Unfortunately It doesn't print. The hover action is fast and not stopping to get a Readable data for getText(). That's why my Query was how to break the Loop, or say Delay the Loop. – Himadri Jun 12 '14 at 12:17
  • 1
    So in that area.. you should do something to click on seats. Is there any other attribute differs between selected and free seats? If so you can make use of that to click on free seats. Post your html code snippet while placing the mouse hover on Seats. – Santoshsarma Jun 12 '14 at 12:20