This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Testing and the fly likes Unable to locate the element while executing TC as JUNIT but it is working fine in IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Unable to locate the element while executing TC as JUNIT but it is working fine in IDE" Watch "Unable to locate the element while executing TC as JUNIT but it is working fine in IDE" New topic

Unable to locate the element while executing TC as JUNIT but it is working fine in IDE

s lekkala

Joined: Jul 25, 2011
Posts: 14

I have recorded one scenario by using slenium IDE, it is working fine while executing the same scenario by using selenium IDE. But while executing the testcases as Junit4(webdriver) and Junit4(Backed selenium) its getting failed to get the frames. Can anyone suggest to solve the problem.

TC which is exported as BackedSelenium:

public void testManagerSelenium() throws Exception {"");
selenium.type("id=txtUserID", "");
selenium.type("id=txtPassword", "rules");"name=pyActivity=Code-Security.Login");
selenium.waitForPageToLoad("30000");"css=#Tab2 > #ACCORANCHOR > #TABSPAN > #RULE_KEY > tbody > tr > td.accord_titleBarBackground");
//--Unable to find this below frames
selenium.selectFrame("PWGadget1Ifr");"id=ManagerApprovalLatest", "label=Approve");
selenium.type("id=ManagerComments", "enter value for the reason");"id=submitButton");

TC which is exportedAs Junit4(Webdirver):

public void testManagerDriver() throws Exception {
driver.get(baseUrl + "/prweb/PRServlet/oO9O9iMscyJc_fy6LnBDXO9xEtRpDxfL3At36r8Aw8k%5B*/!STANDARD?");
driver.findElement(By.cssSelector("#Tab2 > #ACCORANCHOR > #TABSPAN > #RULE_KEY > tbody > tr > td.accord_titleBarBackground")).click();
//----Unable to find the below Frame
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame]]
//----Unable to find the below Frames
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame]]
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame]]

new Select(driver.findElement("ManagerApprovalLatest"))).selectByVisibleText("Approve");
driver.findElement("ManagerComments")).sendKeys("enter value for the reason");

Thanks & Regards,
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
I have not run into this exact issue but I have run into a certain amount of "flakiness" with regards to Selenium and frames. There is a similar thread on the Selenium Issues List which details some of my issue.

I have not found the selenium IDE to be a reliable tool when it comes to frames and such. It could be as much an issue with how the html source is coded to allow for "uniqueness" in element names as it could be with the Selenium tool.

The solution for my problem was to get the elements in the root window matching my Xpath/By clause as well as to pull out all of the frames (getElements(webdriver, By.xpath("//iframe"))) and search through each of them for elements matching the Xpath/By clause. When an element is found, then the click method is executed. Depending on the complexity of the pages you are using, you may also need to consider retrieving frames within frames, etc.
wood burning stoves
subject: Unable to locate the element while executing TC as JUNIT but it is working fine in IDE
Similar Threads
selenium question
selenium, testng, eclipse processing a form
running the selenium(java) script close the browser
Selenium RC Junit test case does not execute.
Junit4+Eclipse+Selenium RC- Test class should have exactly one public zero-argument constructor