8

I am using our existing tool that works perfectly using the Firefox and Chrome implementations of the Selenium IWebdriver.

I am now doing some experimentation using the PhantomJS implementation. So far so good. However, as soon as I want to click a button it does nothing.

I can retrieve the element, however, looking closer at its properties the 'Selected' property states 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 gather this is the cause that my click is not executed, however, I cannot make heads or tails from this error message. using Google did not help either.

Any help would be much appreciated.

Thanks in advance.

WietzeVeld
  • 177
  • 1
  • 8
  • 1
    Try increasing the size of browser window to (1200, 800) while using phantomjs. I had a same issue and it got solved by this. – Vikas Ojha Apr 09 '14 at 12:23
  • Please share your code and HTML of page, only then we can get to the actual problem. – paul Jul 22 '14 at 09:17
  • If you locate your element with ID, try to locate it differently. I had VERY STRAGE situations where locating using ID haven't worked with GhostDriver. – Johnny Aug 21 '14 at 15:41
  • Thanks for all the replies guys, I am sorry I did not get back to this. We decided not to use this driver, despite the possibility of speeding up the test process. – WietzeVeld Aug 26 '14 at 12:26

1 Answers1

8

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
    
Johnny
  • 14,397
  • 15
  • 77
  • 118