Selenium iFrame input text - java

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");

Related

Inspect font/text of a pop-up bubble displayed when a required field is missing value - using Selenium WebDriver

Using Selenium-Java 2.47.1, I see this pop-up bubble/balloon that gets displayed whenever the 'submit' button is clicked and a required field is missing a value. I'm unable to inspect the bubble with firebug or DevTools. I need to be able to get the text and font.
Here is a link to an image of the bubble, it's very simple, I just can't seem to figure this out. Any help is appreciated, thanks!
In Firebug you can select Break On Mutate in the HTML tab (The pause button with brackets). Click the submit button, and Firebug will tell you what element is being added.

Selenium Webdriver (Java) , Need to send "Space" keypress to the website as whole

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();

Unable to inspect element on HTML page (right click inspect element)

For example, go to Yahoo, and try to right click -> inspect element on the arrow button eluded to in the picture below.
Nothing will popup so I'm unable to inspect element, and when inspecting the DOM I cannot seem to locate this element their either.
Any guidance one how to add this functionality back in would be greatly appreciated!
Update: Here is a screenshot of what the DOM looks like when I try to select the element.
The div below the one I have highlighted only selects the pictures and captions between the arrow buttons.
I did got to Yahoo.com, and tried inspecting the element that you have shown. I was able to inspect it normally. [ Im using Chrome, on Mac - Yosemite ].
Here is the code that I found. May be you can use that.
<button type="button" class="FilmstripBtn NextBtn ButtonNaked Wpx-20 Pos-a End-0 T-0 B-0 Fz-30 Z-1 " data-jump-to="next" title="Next" data-action-outcome="pgnt" data-ylk="t1:a3;t2:td;t3:nav;sec:td-fea;elm:btn;elmt:ne;itc:1;" data-rapid_p="6" id="yui_3_12_0_1_1431061078340_1326"><i class="Icon W-a" id="yui_3_12_0_1_1431061078340_1329"></i></button>
Made a little progress. For some reason Chrome still won't let me right click inspect element (maybe a bug), but I was able to find the buttons in the elements tab. They are actually "a" tags and not buttons on my end.
I had difficulty before because they are labeled differently for me than what is shown from the other response to this question, and the "a" tags won't become highlighted unless I expand the divs and select the actual "a" tag (possibly another chrome bug?).

Why don't keyboard keys work in Selenium WebDriver?

I wanted to select an element through keyboard keys in Firefox. I am using this statement
driver.findElement(By.xpath("Element')]")).sendKeys(Keys.ARROW_DOWN);
But when I run it, I couldn't see any movement in the page. I am using JAVA to automate. This issue occurs even in BEHAT\MINK Tool.
My doubt:
is this feature not working because of the developers code?
or I need to modify my code to make it work?
For scrolling page up/down, you can send keys on body tag element of the page, like following:
driver.findElement(By.tagName("body")).sendKeys(Keys.UP); //to scroll up
driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN); //to scroll down

webdriver click on a link in a webpage

I'm trying to click on a particular link in a webpage. Basically this is a Home button. So whereever I browse, I always find this button is same position.
As of now I use driver.findElement(By.xpath("//span/ul/li/a")).click(); command to click on this, but this is not working in all the webpages even though the xpath don't change. here is the firebug view of the link.
the id is not static, it keeps on changing. So what are the other ways I can detect this link ?
You can use By.linktext()
driver.findElement(By.linkText("Home")).click();
As dirkk said, you can always locate an element through a By.linkText() selector, although this could be a fickle solution: the "home" link text could eventually change (in which case your selector won't work anymore), there could be other "home" links on the page (in which case you wouldn't necessarily obtain the element you want) or the "home" link text might be different in a different language (in which case your selector will only work when testing the English site).
If you have control over the generated HTML code, you should try adding a static ID or even a class to this link and look it up through a By.id() or By.cssSelector() selector.
If you don't, try using a selector that relies more on semantics (IDs and classes) than structure (tag hierarchies). That way your selector will be more stable and easier to understand as well. But in the end, that's not always possible if you test an untestable external website.

Categories

Resources