Selenium Webdriver - Unable to find element after page refresh/redirect
Solution 1
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();
Solution 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.
Solution 3
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")));
Siva
Updated on June 05, 2022Comments
-
Siva almost 2 years
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 about 9 yearsHi, 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 <iframe name=a1><frameset><frameset name=fs1><frame name=f1><a id = abcd> 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(); Kindly suggest Regards, Siva
-
Siva about 9 yearsHi, Still im gettitng "No element found" error org.openqa.selenium.NoSuchElementException: no such element
-
Siva about 9 yearsPlease find the HTML hierarchy till the link menu
<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>
-
Vivek Singh about 9 yearsand at which line u r getting exception?
-
Siva about 9 yearsorg.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 about 9 yearsCapabilities [{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 about 9 yearsIn the below command driver.findElement(By.id("abcd")).click();
-
Siva about 9 yearsHi, 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 almost 9 yearsHi, 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 almost 9 yearsHi, 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
-
Vivek Singh almost 9 yearsHi..please provide the html of chrome.