1

I got my code ready in Selenium IDE and exported it to Selenium Webdriver (JUnit 4). My code was working perfectly in Selenium IDE but an issue has arose after my migration to Selenium Webdriver.

The issue is on a click!

In Selenium IDE

Command: Click
Target: id=vdc_div2

In Selenium Webdriver

driver.findElement(By.id("vdc_div2")).click();

All the other clicks in Selenium Webdriver are working apart this. It doesn't find this element and gives a NoSuchElementException: Unable to locate element. I have also tried different locators, such as xpath and css.

The html for this is as follows.

<div id="pmc_vdc_items" class="row clearfix pmc-row">
 <div id="vdc_div0" class="pmc-selection-tile-large">
  <div id="vdc_div1" class="pmc-selection-tile-large">
   <div id="vdc_div2" class="pmc-selection-tile-large pmc-selection-tile-large- active">
    <div id="vdc_div3" class="pmc-selection-tile-large">
    </div>

Please help me out.

8
  • Your HTML didn't attach. Can you post the xpath that you tried as well?
    – VolleyJosh
    Nov 17, 2014 at 16:40
  • Is the element inside of an iframe?
    – Sam Woods
    Nov 17, 2014 at 19:47
  • @VolleyJosh The xpath is /html/body/div/div/div/div/div/div/div[2]/div[2]/div/div[2]/div[3] and the minimal xpath is //*[@id="vdc_div2"]. I have tried both. Works on Selenium IDE but doesnt on Selenium Webdriver. Nov 18, 2014 at 7:03
  • @SamWoods The element is an div itself. It is not in a iframe. You can see the html Nov 18, 2014 at 7:05
  • The detailed html is as follows <div id="pmc_vdc_items" class="row clearfix pmc-row"> <div id="vdc_div0" class="pmc-selection-tile-large"> <div id="vdc_div1" class="pmc-selection-tile-large"> <div id="vdc_div2" class="pmc-selection-tile-large pmc-selection-tile-large-active"> <div id="vdc_div3" class="pmc-selection-tile-large"> </div> Nov 18, 2014 at 7:08

2 Answers 2

0

there will be 2 reasons :

  1. Maybe it is trying to click the button before page loads completely in this case you should use wait()
  2. Maybe that button is located in iFrame in this case u need to move to iFrame and then click on button
0

This seems to be the case where you try to find the element (using findElement) before the page completely loaded its content. At that moment, the element might not exist.

Selenium itself already waits for the page to load. But in some cases (JavaScript execution, for example), it doesn't know the page content is fully loaded. So, you need to add robustness to your test by doing an Explicit Wait. Please see: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

You need to wait (until a timeout period) for a given expected condition to occur before proceeding.

I am not sure this is your problem, but I hope this helps.

1
  • I have used the implicit wait, the explicit wait and even 'Thread.sleep(10000). Nothing seems to work! Nov 19, 2014 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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