Selenium WebDriver传入Debug但不是经常运行

时间:2016-01-28 01:01:05

标签: java selenium intellij-idea

我确实是Selenium WebDriver的新手,但是我在IntelliJ中进行基本测试时遇到了麻烦。如果我在代码中放置断点并在调试模式下运行它并逐步完成步骤,我就可以运行并通过测试。但是,当我只是单击定期运行时,它在第二步失败,说下面的内容:org.openqa.selenium.WebDriverException:元素在点(596.5,1128.63330078125)处不可点击。其他元素将收到点击:

我一直试图弄清楚为什么它会在Debug中按预期传递并运行,但不是在我经常运行时。这是我的考试:

公共类BF_Test {

private WebDriver driver;

@Test
public void checkURL()
{

    WebDriver driver = BrowserFactory.getDriver("firefox");
    driver.get("http://www.vizio.com");

    WebElement homePagePopup = driver.findElement(By.xpath("//div[@id='modal']/div/a"));
    homePagePopup.click();

    //NEED TO FIGURE OUT WAIT TIMER OF SOME SORT
    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("html body.cms-index-index.cms-index div.page-wrapper div.main.col1-layout div.std section#heroslider.kslider.hero-home.section-wrap.section-wrap-primary div.navi-wrap ul.navi.navi-bind.navi-count-3 li.item-0")));

    WebElement naviButtonsCarousel = driver.findElement(By.cssSelector("html body.cms-index-index.cms-index div.page-wrapper div.main.col1-layout div.std section#heroslider.kslider.hero-home.section-wrap.section-wrap-primary div.navi-wrap ul.navi.navi-bind.navi-count-3 li.item-0"));
    naviButtonsCarousel.click();

    WebElement homePageTVPButton = driver.findElement(By.cssSelector("#tvp-marquee-inner > div.container > div.content > a.vz-btn"));
    homePageTVPButton.click();

    WebElement resultsAreInValidation = driver.findElement(By.cssSelector(".thanks.fade-in"));
    System.out.println(resultsAreInValidation.getText());

    WebElement robinsonBtn = driver.findElement(By.cssSelector("#robinsonHomeVote > span"));
    robinsonBtn.click();

    WebElement robinsonPlayerText = driver.findElement(By.cssSelector("#modal-container > div > div > div.player > div.playerInfo > section > h1"));
    Assert.assertEquals("Verify that Allen Robinson text is on the page","Allen Robinson",robinsonPlayerText.getText());

    WebElement btnClose = driver.findElement(By.cssSelector("button.close"));
    btnClose.click();

    driver.quit();
}

}

正如你所看到的,在我尝试做的事情中,没有什么可以报告的。只需打开一个网站,点击几个链接并断言一些文字和诸如此类的东西。

有什么想法让我能为我工作吗?我一直在搞乱WebDriverWait,看看它是不是太快了......但似乎没有任何帮助。

谢谢!

3 个答案:

答案 0 :(得分:2)

WebDriverException: Element is not clickable at point表示您要点击的元素不可见。您可以通过在单击之前滚动到元素来解决它。

WebElement element = driver.findElement(By.cssSelector("selector"));

Actions actions = new Actions(driver);
actions.moveToElement(element).build().perform();

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(element)).click();

答案 1 :(得分:1)

使用Selenium,3.0:

,使用C#中的以下说明为我工作
Thread.Sleep(TimeSpan.FromSeconds(15));

然后我可以创建webElement并发送事件点击。

答案 2 :(得分:0)

创建如下扩展名:

 public static class WebDriverExtensions
{
    public static IWebElement FindElementUntil(this IWebDriver driver, By by, int waitSeconds = 15)
    {
        var wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(waitSeconds));
        wait.Until(driver => driver.FindElement(by));
        return driver.FindElement(by);
    }
}