Element.Click fails when using the PhantomJS selenium web server in .Net

I am using our existing tool that works great using Firefox and Chrome Selenium IWebdriver implementations.

Now I'm experimenting using the PhantomJS implementation. So far, so good. However, as soon as I want to press a button, it does nothing.

I can extract the element, however, looking closer to its properties, the "Selected" property contains the following:

Error Message => 'Element is not selectable' caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Close","Host":"localhost:37704"},"httpVersion":"1.1","method":"GET","url":"/selected","urlParsed":{"anchor":"","query":"","file":"selected","directory":"/","path":"/selected","relative":"/selected","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/selected","queryKey":{},"chunks":["selected"]},"urlOriginal":"/session/fcaf88a0-40b4-11e3-960d-bdce3224aacf/element/%3Awdc%3A1383063211142/selected"} 

I would understand that this is the reason why my click is not executed, however I cannot make error messages from this. using google didn't help either.

Any help would be greatly appreciated.

Thanks in advance.

+8
selenium phantomjs selenium-webdriver ghostdriver
source share
1 answer

We had many similar problems with PhantomJS.

So, a couple of steps to find out what the root is.

  • Set the screen size (as indicated in the comments, PhantomJS uses 400x300 by default):

     driver.Manage().Window.Size = new Size(1920, 1080); //Size is type in System.Drawing" 
  • Use to make sure your item is actually visible:

     new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login)))); 
  • Click on an item with Javascript

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

For Java, this will be as follows:

  • Screen size

     driver.manage().window().setSize(new Dimension(width, height)); 
  • Visible Element Visible

     WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOCATOR"))); 
  • JS Click

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

All Articles