Firstly, I have tried driver.switchTo().frame("framename"); but it does not switching to that.
driver.switchTo().frame("xxx");/// Throws an {"status":7,"value":{"error":"no such element","message":"An element could not be located on the page using the given search parameters."}}
After dig into deeper, I found that the particular frame locators were not even present inside the page source. Any idea on how to switch to that frame.
P.S. I'm using WinApp driver.
Note: Same scenario in web, I'm able to switch using switchTo iframe elements.
I think you have a mismatch here. What you need to input at frame(" ") is not a string. It should be:
driver.switchTo().frame(driver.find_element_by_xpath("xpath of the iframe"));
Related
I'm trying to select an iframe in selenium java but the element doesn't have a Name or Id attribute. How should I get it? (I want to use the switchTo to switch to it)
The website I am trying to get the iframe from is jklm.fun and the xpath of the iframe is
"/html/body/div[2]/div[4]/div[1]/iframe"
(you need to be in a game for the iframe to exist)
Same way you select anything, based on their tree position: regular CSS selector. You query-select body div div div iframe and you're almost certainly going to get it (unless you have lots of three-deep divs with iframes in them, in which case what on earth is going on on that webpage =), but if that still gives you multiple options, narrow the query selector using tactical :nth-child(...) pseudo-classes.
I would not suggest to go with absolute xpath :
/html/body/div[2]/div[4]/div[1]/iframe
rather have a relative xpath.
Having said that, as far as switching is concerned, there are multiple ways:
Using driver.switchTo()
This basically provides 3 overloaded methods: -
with index :-
driver.switchTo().frame(index)
with name or ID:-
driver.switchTo().frame(nameOrId)
with web element
driver.switchTo().frame(frameElement)
so out of these 3, we can easily use 2 of them since id or name isn't available in your case.
Using the index:
driver.switchTo().frame("here pass the index if you know. ")
Using frame web element:
driver.switchTo().frame(driver.findElement(By.xpath("/html/body/div[2]/div[4]/div[1]/iframe")))
this should work for you.
The other way we have is with Explicit waits:
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("/html/body/div[2]/div[4]/div[1]/iframe")));
This is more convenient, way to switch to iframe in angular or react based Application.
I am working on one selenium project. My scenario is, I have multiple forms one after another. After filling them I have to click on the Next button. I have 4 pages with the next button and they have the same XPath. When I try to use the same web element for the next button it works once but when I try to use that same thing again on a different page It shows element intreactable error.
I would try the following to identify why you get the interactable error (it would help to give us the error at least as is found on the Selenium Documentation)
try to click using javascript executor,
try to add webelements for each action you need to perform (so 4 webelements for each 'Next' button). If it works in this way maybe the webelement is not refreshed after you use it (maybe is a static field). Try also to work with Page Factory pattern.
If nothing works, we should receive more information to be able to help.
I am a beginner in Selenium Automation, and stuck with a situation, where, if I open a page xyz.com, and login, then there are some text box and dropdown and buttons to be clicked but the thing is, after the driver get to that page, I can see those elements, and can get the ID and necessary tags, but these whole page consist of 3 different (.do) page.
For example:
1. main page is abc.do
2. left panel is mno.do
3. center is xyz.do
Image of Inspect Element in IE
and my elements exists in xyz.do, and links in mno.do.
I am using eclipse to code, Selenium 3.1, IE 11
How can I switch between them so that my driver can find the elements, write now its showing element cannot be found, and when I pulled the source code its providing of only first .do page.
Please help.
Thanks.
It seems the page is using frames or iframes, but because you do not provide a URL, it's only a guess.
So, to switch a frame/iframe, simply use the switchTo method:
driver.switchTo().frame0); // Frame by number
driver.switchTo().frame("iframe1"); // Frame by selector
After that call, you switch into the "context" of that page/frame/iframe.
Recently I have been tasked with Automating MS CRM 365 with Selenium Automation. I have opted for Using Gradle and Java for this, using IntelliJ.
Currently my issue is when I am on a form page, I am unable to access any elements on that page for data entry or drop-down selection.
I have tried using iFrame switching:
driver.switchTo().frame(driver.findElement(By.cssSelector("#contentIFrame0")));
I have tried selecting from ID, from XPATH & from CSS.
The code is a simple driver.findElement; there isn't anything special about it. I seem to be failing at the most basic part.
driver.findElement(By.id("firstname_i")).click();
Expected outcome: To be able to access the element and process a Click, followed by either a selection from drop-down or a text entry.
Actual outcome:
org.openqa.selenium.NoSuchElementException: Unable to find element with css selector == #firstname_i
Image to Firefox Inspection of the Element
I was wondering if there is something in the CSS that's stopping me from accessing the element. I noticed that the element for the 'text' box is under a few layers and is not displayed, unless the top layer is accessed. However I cannot event find that element to follow the flow. Hope that makes some sense.
So after a bit of playing about, I noticed that my iframe switch was working however the element I was trying to access was correct just not complete, not sure if this is ever relevant to anyone else but I had to add a method to counter my element issue by select the initial element "name" and then selecting a second element as the input "name_i".
Where as if I tried to select "name_i" initially I get the whole "element not found" as the CSS sets it to invisible unless activated by mouse over/ click on the first element (overlay?).
This seems to be the case across the whole form page.
Never worked with MS 365 before so I have no idea if this is viable or even common.
Thanks.
I am searching for an element on a webpage by using its XPath. The XPath is correct and can find the element ONLY if I manually perform a click anywhere on the page first. If I do not do this before the statement runs it will not find the element.
I have tried many different attempts to allow focus on the page:
selenium.selectWindow(null);
selenium.fireEvent(xpath, "focus");
selenium.click(element on page);
selenium.mouseDown();
selenium.mouseUp();
After performing these functions the statement will still not find the element, but if I manually maximize the page and click anywhere on the page, then run the statement, the element is found. Can anyone help me out with this?
The statement I am using to find the element is:
selenium.isElementPresent("//div[#class='sample_class']");
Thanks!
Instead of using XPath, try using the CSS selector for that item.
Use selenium.isElementPresent("css=div.sample_class"); as your selector. Saucelabs have explained it quite well at http://saucelabs.com/blog/index.php/2009/10/selenium-tip-of-the-week-start-improving-your-locators/