2

I am trying to write some UI test cases for an SAP-webUI (web based) application. After login, it shows the dashboard ( Workcenter's ) screen.

Now the problem is, I am able to open the page, enter U/N, Pwd and login through Selenium. After i press the "Login" button the URL changes and the page got redirected/refreshed.

E.g. URL before login : https://a/b/c/d/e/f/g.htm?sap-client=001&sap-sessioncmd=open

E.g. URL after successful Login : https://a/b(bDsdfsdsf1lg==)/c/d/e/f/g.htm

After this im unable to perform any action or press any link in any part of the page. I tried with all the possible attributes ( css, xpath, id ). Webdriver was unable to find any element on the page. It shows the error "No element found" alone.

I am using java with Selenium Web Driver.

Please find the html structure of the webpage below

<html><body><div><div><iframe>#document<html><head></head><frameset><frameset><frame>#document<html><head></head><body><form><div><div><table><tbody><tr><td><div><ul><li><a id=abcdef></a></li></ul></div></td></tr></tbody></table></div></div></form></body></html></frame></frameset></frameset></html></iframe></div></div></body></html>

Actually i want to click a linkmenu "abcd", which is inside iframe and frame as shown in the below HTML code

<html><head></head><body><iframe name=a1><html><head></head><frameset><frameset name=fs1><frame name=f1><html><head></head><body><table><tbody><tr><td><ul><li><a id=abcdef>

I tried the below code as well.

driver.switchTo().frame("a1"); driver.findElement(By.id("abcd")).click();

OR

driver.findElement(By.xpath("//*[@id='abcd']")).click();

After using the above code, still im getting the error "No such element"

Kindly suggest

Regards, Siva

Siva
  • 39
  • 1
  • 3
  • 7
  • Switch to iframe then switch to the frame contained within that iframe. – Vivek Singh Mar 25 '15 at 19:14
  • I tried the below code, it shows no such frame exist driver.switchTo().frame("a1"); driver.switchTo().frame("f1"); driver.findElement(By.id("abcd")).click(); – Siva Mar 26 '15 at 10:15

3 Answers3

4

Do it this way...

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@name='a1']"))); // switching to iframe

followed by

driver.switchTo().frame("f1"); // switch to frame

and then your desired action...

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

Vivek Singh
  • 3,641
  • 2
  • 22
  • 27
  • Hi, Still im gettitng "No element found" error org.openqa.selenium.NoSuchElementException: no such element – Siva Mar 26 '15 at 10:45
  • Please find the HTML hierarchy till the link menu ` – Siva Mar 26 '15 at 11:16
  • and at which line u r getting exception? – Vivek Singh Mar 26 '15 at 11:36
  • org.openqa.selenium.NoSuchFrameException: no such frame (Session info: chrome=41.0.2272.101) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) – Siva Mar 26 '15 at 12:09
  • Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=C:\Users\AppData\Local\Temp\scoped_dir9152_7396}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=41.0.2272.101, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}] – Siva Mar 26 '15 at 12:09
  • In the below command driver.findElement(By.id("abcd")).click(); – Siva Mar 26 '15 at 12:25
  • Hi, Im getting no frame found error only in chrome. In IE and firefox it is working fine. Can you provide me the suitable code to use in chrome @alecxe – Siva Mar 26 '15 at 14:42
  • Hi, The above code works fine in IE. But not in chrome. If i execute it in chrome it shows 'No frame found' Kindly help – Siva May 07 '15 at 09:49
  • Hi..please provide the html of chrome. – Vivek Singh May 07 '15 at 16:53
2

This is because of the iframe. You need to switch to it first:

driver.switchTo().frame(0);
driver.findElement(By.id("abcdef")).click();

where 0 is a frame index.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Hi, After using the above code, still im getting the error "No such element" as below. org.openqa.selenium.NoSuchElementException: no such element Actually i want to click a linkmenu "abcd", which is inside iframe and frame as shown below – Siva Mar 26 '15 at 09:59
  • Hi, Im getting no frame found error only in chrome. In IE and firefox it is working fine. Can you provide me the suitable code to use in chrome @alecxe – Siva May 07 '15 at 09:51
1

See doc on implicit wait here

I guess you should do a implicit wait until your chosen element is available

modify these code to suit your chosen element:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
unifreak
  • 773
  • 6
  • 17