Webdriver:在会议条件上打破循环

时间:2014-06-12 10:23:20

标签: java html selenium-webdriver

我正试图将鼠标悬停在所有座位上,然后点击可用座位。但是一旦找到可用的座位,我就无法打破webelement Loop。它悬停在某个座位上,从不点击任何一个。

这是我的代码......

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

1 个答案:

答案 0 :(得分:0)

是评论中提到的Shail016你应该使用equals方法比较两个字符串而不是==。

请参阅以下主题以更清楚地了解字符串比较

Java String.equals versus ==

尝试使用以下代码。

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");

            }
        }