Selenium Webdriver - Unable to find element after page refresh/redirect

3,102 views
Skip to first unread message

Siva

unread,
Mar 25, 2015, 9:21:26 AM3/25/15
to webd...@googlegroups.com
Hi,

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 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.

<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>

I am using java with Selenium Web Driver.

Please find the html structure of the webpage below

I want to click the id **abcdef** which is present in the above html code

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

Kindly help.

Regards,
Siva

Shravan Kumar

unread,
Mar 25, 2015, 10:11:45 AM3/25/15
to webd...@googlegroups.com
Hi Siva Kumar,

After going through your html code, I think you are attempting to locate an element in the iframe.
See, you cannot locate an element in an iframe set like we do on general html document.
You need to switch to iframe before locating an element in the iframe set.

Try this code..

driver.switchTo().frame(driver.findElement(By.id("your required element id")));

Hope this would help you, and please correct me if I made anything wrong here.

Thank you,

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.



--
with regards,
Shravan Kumar.T

Siva

unread,
Mar 26, 2015, 4:41:08 AM3/26/15
to webd...@googlegroups.com

Hi Shravan,

After using your code, still im getting the error "No such element" as below.

org.openqa.selenium.NoSuchElementException: no such element

 
I tried the below code as well.
 
driver.switchTo().frame("CRMApplicationFrame");

driver.findElement(By.className("th-lk")).click();

OR
driver.findElement(By.xpath("//*[@id='C4_W16_V17_YMKT-ACLEA']")).click();

Kindly suggest

Regards,
Siva

Shravan Kumar

unread,
Mar 26, 2015, 11:34:16 PM3/26/15
to webd...@googlegroups.com
Hi Shiva,

Does your page contain multiple frames?

If the page has multiple frames, then the first frame would be at index "0", and the second frame would be at index "1".
Once the frame is selected, the driver focuses on that particular frame only. So, the operations we try to perform on the page other
than the selected frame will not work and throws "no such element" error. So, try to choose the frame id properly.

If the frame id is "shravan" (just an example), then driver.switchTo.frame("shravan");

try{
driver.switchTo.frame("shravan");
syso("frame selected");
}
catch(NoSuchFrameException e)
{
syso("unable to find frame" + e.getStackTrace());
}
catch(Exception e)
{
syso("unable to find frame" + e.getStackTrace());
}

Always select a frame by its name or it ID.
Or select a frame using its previous web element.

Please have a look at this site and try them slowly step by step.

Please try to understand your html page first, go through your html source code step by step using firebug and analyse it and then write the code. These errors will happen all the time.

For frames and dynamically changing element, never use xpath because frames can be tend to change dynamically whenever web developers wants to change and also can add tags dynamically after some operations.

Hope this will help you and correct me if I said anything wrong,

thank you,

--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webdriver+...@googlegroups.com.
To post to this group, send email to webd...@googlegroups.com.
Visit this group at http://groups.google.com/group/webdriver.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages