i am trying to navigate through pages using selenium web driver and i am stuck at one point
please refer to the image where i have shown the output of inspect element for that page that i am working on.
but in the page source (which i saw on the browser and also using Jsoup) looks like this,
<html>
<head>
</head>
<frameset rows="75,60,*" resize="no" SCROLLING="NO" name=main border="0">
<frame src="/frame/topnewprof.shtml" name="top" SCROLLING=NO>
<frame src="/frame/blank.html" name="menu" SCROLLING=NO >
<frame src="/itrade/user/welcome.exe?action=chk_seckey_stat" name="body" SCROLLING=AUTO>
</frameset>
<body>
</BODY></html>
why is this mismatch? and the yellow stuff that i have highlight in the image above has the element that i need!!
how will i get there using selenium??
i know that we can navigate into the iframe using selenium's switchTo().frame() but even if i get into any of the three frames as shown above in the page source information, i'm not able to find the information i need,
can this be achieved ? is it even possible?
UPDATE:
hello guys! i found the solution to this and now that huddle is crossed.
actually what happened was , when i was trying to do getPageSource, selenium was actually getting the frame source of one of the frames ("body" - as mentioned above), i accidentally figured that out.
Next to solve my problem i wanted to come one step back from where i was so i can select this iframe = (name="top") which was the target where i had the content as shown in the image. to Achieve this i used Selenium's defaultContent() function and came back one step then with switchTO().frame() went into the frame of my desire and accomplished the task
hope this helps!!
and thanks for everyone who tried to help me on this.
I couldn't exactly tell you why this mismatch is caused but I have an idea of how you could solve this problem.
I had similar problems with javascript phrases on pages. Normally such elements have to be clicked to get into. But if this element isn't clickable or a click doesn't sole the problem you could also search the information you need by using unique Xpath's.
I'm not sure if you using Selenium IDE already but maybe you could record navigating to this element and use the thrown java code from the Selenium IDE to get the required Information.
... I only have seen this problem while using Selenium remote control not the Selenium WebDriver...
I think the problem could also be solved by using xpaths. The easiest way to get the correct xpath is using firebug with firefox. Right click on the element in developer tools and click copy xpath. Firebug's incredibly accurate when producing xpaths. It has solved many problems like that one for me.
*Even if you aren't using firefox, most of the time you can use the same xpath from firebug in chrome webdriver testing.
It's a life saver.
Warning though, sometimes the path is long like:
final static String planTitlePath = "/html/body/div[1]/div[2]/div[1]/div[2]/div[5]/div/div/div/div/section/div/div[2]/div/ol/li/div[1]/plan-card/h4/span";
i found the solution to this and now that huddle is crossed. actually what happened was , when i was trying to do getPageSource, selenium was actually getting the frame source of one of the frames ("body" - as mentioned above), i accidentally figured that out. Next to solve my problem i wanted to come one step back from where i was so i can select this iframe = (name="top") which was the target where i had the content as shown in the image. to Achieve this i used Selenium's defaultContent() function and came back one step then with switchTO().frame() went into the frame of my desire and accomplished the task
hope this helps!! and thanks for everyone who tried to help me on this.
Related
I have an element to find:
//div[contains(#class, 'bPageBlock')][.//*[.='Agreement Documents']]//div[#class='pbBody']//tr[contains(#class,'dataRow')]//a[text()='View']
The problem is, this finds two elements and I want only one. One is under an iframe and one isn't. It would be easy if I wanted the one under the iframe. I could do
//iframe///div[contains(#class, 'bPageBlock')][.//*[.='Agreement Documents']]//div[#class='pbBody']//tr[contains(#class,'dataRow')]//a[text()='View']
However, as you probably guessed, I want the one that is NOT under the iframe. I don't know how to specify something like //not iframe//. And even if I could, the // would find something one step lower or higher that was not an iframe.
Any suggestions how to find the one NOT under the iframe. The roots and paths other than that all seem to be the same with each other. I have tried lots of different things.
If you want to see the specific iframe:
<iframe frameborder="0" id="RLPanelFrame" name="RLPanelFrame" src="/emptyHtmlDoc.html" title="Hidden Frame - Ignore" style="height: 176px;"></iframe>
Then there are many sub-units under it with auto-generated meaningless IDs.
I don't think I can find each one using driver.find() and get the full xpath and check for "iframe" because selenium does not have an xpath extractor. I guess for each one I could keep getting the parent until I got to //html or //iframe but that would take a long time.
Any suggestions? This with Java and Selenium
I am using Selenium to build a test automation where the html is in an iFrame, I was able to find online the lines of code to activate the iFrame, click on a link, and press a button and they are working fine -see following lines:
driver.SwitchTo().Frame("06634000000BVL6");
driver.FindElement(By.LinkText("Loan Details R1")).Click();
driver.FindElement(By.XPath("//button[contains(.,'Edit')]")).Click();
I needed to input a text within a textBox in that iFrame, but I couldn't handle the ID or the Class, below is the HTML for the input:
Any thoughts ?
Thanks for your help
I can't comment yet, so this will be part answer, part comment.
Based on what you have posted, it looks like you may not be in the correct iframe and we don't have enough of the code from the webpage to tell if there is an additional iframe.
I'd also like to see the code you are using to write text to the field, you may have an issue there.
If you don't and the only issue you have is the selector then try the following. Go get the developer version of firefox. Navigate to your webpage in firefox. Inspect the element where you want to write text to. Once you are in the inspection screen, there is a path bar that can scroll left and right at the bottom of the screen. Check that to confirm that there is only the one iframe you mentioned and that you are in the correct iframe. If that is the issue, you should be good to go, you're code above works for switching between frames. If you are in the right iframe, then try a different method of finding the element for the text box. I have had the most success with hard to find elements by using the cssselector. To get the cssselector for the element right click on it, navigate to copy and then cssselector. From there your code should look like this (using c#):
driver.FindElement(By.CssSelector("INSERT CSS SELECTOR HERE")).SendKeys("Text");
I pressed F12 in Chrome, and I can see my code.
How do I copy the code. (see screenshot)
I am able to press ellipses on the left, select Copy, then select Copy Element.
It copies into buffer and I can paste from it.
But whatever I get is not well formatted.
If I want to be able to ask a question on the board about something, this sort of paste would be very unfriendly for the person wanting to answer the question.
Screenshot
Try to copy the first or second line that will bring you the whole html. The exact line is
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>...
Try to copy outerHTML. I don't know if this works or is what you want.
The best thing I have found it to save as xml and attach.
You can also take screenshots of html code when you post question to board.
Reason is that nobody really modifies the source code of the website.
For best results in copying HTML code from a website, I recommend using the free version of CoffeCup HTML editor
EDIT: A better way to do this within Chrome itself is to put "view-source:" before the website name. Example: view-source:http://example.com. It is formatted the way the website wrote it.
I have a few nav bar items that I am trying to find with driver.findElement(by.id("menu-news-menu-item")) and driver.findElements(by.id("menu-news-menu-item")). It can't find them for some reason. I have verified that the id is correct on the site but it still can't be found. I know there are other ways to get to the info, but it is my understanding that using the id is the best way to go about finding elements. Below I have included an HTML snippet of what I am trying to search for. If I need to provide any more information please let me know.
<div class="navbar-collapse collapse">
<li>
<a id="menu-news-menu-item" href="/novus/news">News</a>
</li>
</div>
From looking at your HTML I see one potential problem. There may be more.
The top level DIV you posted has a class navbar-collapse collapse. That indicates to me that that DIV is collapsible and is currently collapsed which means that any of its children will be hidden. Selenium was designed to allow the user to only interact with visible elements. This means that if you search for your A tag by ID and it's a child of the DIV that is currently collapsed, Selenium won't find it. What you need to do before you search for the A tag is to unhide it. I don't know for sure how to do this but it probably involves clicking the collapsible DIV.
With this info, try to figure the rest out on your own. You should be able to investigate the page HTML, try some code, and see what happens. If it doesn't work and you get stuck. Come back and post some more of the surrounding HTML, the code you tried, and the result (error messages, etc.) and we'll try to help you more.
My problem is as follows.
I am attempting to automate part of a test suite for a website I work in, and while most of it went well, I'm at the point where the developers added a lightbox to confirm the next action.
Using firebug I found out an xpath I could use to click the button I need to proceed, but sadly it isn't working.
After some manual attempts, I figured that pressing the "Space" key, I can proceed.
The problem is that any sort of try using "driver.findElement" be it by xpath, or link text, fails with a "No such element" error in console.
So I'm trying to just send the keypress of Space , without using find element.
To be clear, I want to emulate someone just pressing space without clicking or selecting anything beforehand.
I tried with driver.Keyboard... but "Keyboard" isn't recognized, so I'm at a loss of how to send this keypress without using driver.findElement.
The piece of code giving me problems is:
driver.findElement(By.xpath("//div[4]/div[3]/div/button")).click();
Any help would be appreciated.
Thank you and have a great day!
If you receive NoSuchElementException, but you know that the element is there, then it seems that the element get loaded into the DOM later (with ajax?), than the page get loaded.
In this case you should use Implicit or Explicit Wait to wait until an element present, or an element is visible, etc...
If it still doesn't work, and you want to try the Space Key thing, then you can perform it on any element, for example on the <body> tag:
WebElement body = driver.findElement(By.tagName("body"));
body.sendKeys(Keys.SPACE);
Hope it helps.
try this:
Actions action = new Actions(Driver);
action.SendKeys(Keys.Space).Build().Perform();