Element.Click not executed when using PhantomJS selenium webdriver in .Net Element.Click not executed when using PhantomJS selenium webdriver in .Net selenium selenium

Element.Click not executed when using PhantomJS selenium webdriver in .Net


We had a lot of similar issues with PhantomJS.

So, couple of steps to figure out what the root cause to it

  1. Set you screen size (as suggested in comments; PhantomJS uses 400x300 by default):

    driver.Manage().Window.Size = new Size(1920, 1080); //Size is type in System.Drawing"
  2. Use to verify that your element is actually visible:

    new WebDriverWait(driver,TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login))));
  3. Click on the element with Javascript

    IJavaScriptExecutor js = _driver as IJavaScriptExecutor;js.ExecuteScript("arguments[0].click();", buttonToClick); //buttonToClick is IWebElement

For Java it would be as follows:

  1. Screen size

    driver.manage().window().setSize(new Dimension(width, height));
  2. Verifying element is visible

    WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOCATOR")));
  3. Clicking with JS

    JavascriptExecutor js = (JavascriptExecutor)driver;js.executeScript("arguments[0].click();", buttonToClick); //buttonToClick is WebElement