简体   繁体   中英

Selenium WebDriver passes in Debug but not when regularly run

I'm admittedly REALLY new to Selenium WebDriver, but I've hit a snag when running a rudimentary test in IntelliJ. I'm able to run and pass my test if I put breakpoints in the code and run it in Debug mode and step through the steps. However, when I just click run regularly it fails on the 2nd step saying the following: org.openqa.selenium.WebDriverException: Element is not clickable at point (596.5, 1128.63330078125). Other element would receive the click:

I'm stuck on trying to figure out why it would pass and run as expected in Debug, but not when I run regularly. Here's my test:

public class 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();
}

}

So as you can see, nothing crazy to report in what I'm trying to do. Just open a website, click on a couple links and assert on some text and whatnot.

Any thoughts on what I can do to get this to work for me? I've been messing around with WebDriverWait to see if it was Selenium being too quick...but nothing seems to help.

THANKS!

WebDriverException: Element is not clickable at point means the element you want to click on is not visible. You can solve it by scrolling to the element before the click.

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

Works for me, with the following instructions in C# using Selenium, 3.0 :

Thread.Sleep(TimeSpan.FromSeconds(15));

and then I can create the webElement and send event click.

create an extension like so:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM