On clicking the link:

<a href="#">xxx</a>

the below div should be appended to the webpage

<div class="desc cloned">
<div class="wrap">                                             
    <div class="desc_wrap">
        <div class="heading">xxx</div>
        <div class="price">Standard</div>
        <div class="text">Some Text</div>
    <div class="close"></div>

I have created the phantomjs driver as: I have created the driver as below:

DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setCapability("takesScreenshot", true);
caps.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS,new String[]{"--ignore-ssl-errors=yes","--ssl-protocol=any","--web-security=false"});
caps.setCapability("applicationCacheEnabled", true);
caps.setCapability("handlesAlerts", true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[] { "--logLevel=2" });
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, PhantomJSpath);
caps.setCapability("phantomjs.page.customHeaders.Accept-Language", "en-GB");
driver = new PhantomJSDriver(caps);

and to click the link:


This code is working for firfox driver. In phantomjs there is another block where the same code works except that the css_class of the division to be added is different.

  • Can you be more clear with this question. Right now this is vague and unclear. – demouser123 Dec 8 '15 at 11:27
  • After a link is clicked a new div is shown. This is what is expected and this happen when i execute it in webdriver firefox driver. But when i change the driver to phantomjs, the division is not shown. – Rita Agarwal Dec 8 '15 at 12:48
  • Can you share the exception, if any? Otherwise, check out this similar question. – kirbycope Dec 8 '15 at 16:57
  • The exception is: org.openqa.selenium.NoSuchElementException: {"errorMessage":"Unable to find element with css selector 'div.desc.cloned > div.wrap > div.desc_wrap > div.heading'" – Rita Agarwal Dec 9 '15 at 5:01


  • It may happen that LinkText can be recognize by ff and not be phantomJS. This possibility has very less chances.
  • Can you give a try and use other locators like

    1. We can just use as

'link=Forgot your password?', using xpath we should use as //a[.='Forgot your password?']

  1. We can also specify the partial text of the link as

//a[contains(text(),'Forgot')]. This also can be written as //a[contains(.,'Forgot')]

  1. In Css we rewrite them as


4.1 Some times we may need to work with URLs with href attributes. The below xpath can also be used instead of finding the link text.


4.2 With Css


Hope this helps !



The error suggests the element is not there in PhantomJS at the moment of findElement();

You should try a WebDriverWait before using the findElement, since findElement does not wait for the element to appear. It just checks is it here now and if not throw exception. The wait should wait for a maximum of 30 seconds by default. I suspect this is the issue as most browsers behave differently

Otherwise PhantomJS is not retrieving the page at all, check if you can verify it is being loaded somehow. Like logs, debugging, etc...

Not the answer you're looking for? Browse other questions tagged or ask your own question.