3

I'm new to Selenium Webdriver and I have a problem with a dropdown menu. I compiled my code but sometimes it returns the error:

org.openqa.selenium.NoSuchElementException: Unable to find element with id == i_ACAD (WARNING: The server did not provide any stacktrace information) 

Sometimes it executes the script normally.

I really do not know how to resolve this problem.

A piece of my html code:


<li id = "i_ACAD" title="Register">
<a class ="TemSub" tabindex="25"> Register </a>
</li>

<li id = "i_MPG" title="Menu Payment Profile"> 
 <a class="TemSub" tabindex="45"> Payment Profile </a>
</li>

My code:

driver.switchTo().frame(driver.findElement(By.id("frmmenusuperior")));

Thread.sleep(3000);

WebElement menu = driver.findElement(By.xpath("//*[@id='i_ACAD']/a"));

Actions actions = new Actions(driver);

actions.moveToElement(menu).perform();

WebElement submenu = driver.findElement(By.xpath("//*[@id='i_MPPG']/a"));

Actions subactions = new Actions(driver);

subactions.moveToElement(submenu).perform();
3

Check with different xpath & use implicitly wait instead of 'Thread.sleep' -See below

driver.switchTo().frame(driver.findElement(By.id("frmmenusuperior")));   
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

WebElement menu = driver.findElement(By.xpath("//li[@id='i_ACAD']/a"));
Actions actions = new Actions(driver);   
actions.moveToElement(menu).perform();

WebElement submenu = driver.findElement(By.xpath("//li[@id='i_MPPG']/a"));   
Actions subactions = new Actions(driver);   
subactions.moveToElement(submenu).perform();
  • Thank you, but it not resolved my problem, I continue with the same problem. – Malfus Apr 22 '16 at 12:31
  • plz attach screen of your drop down here.... – Bharat Mane Apr 25 '16 at 11:15
0

Use following code that may help :

 driver.switchTo().frame(driver.findElement(By.id("frmmenusuperior")));
    Thread.sleep(3000);
    WebElement menu=driver.findElement(By.xpath("//ul//li[@title='Register']//a"));
    Actions actions = new Actions(driver);
    actions.moveToElement(menu).perform();
    WebElement submenu = driver.findElement(By.xpath("//ul//li[@title='Menu Payment Profile']//a"));
    Actions subactions = new Actions(driver);
    subactions.moveToElement(submenu).perform();

Please let me know if it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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