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.
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.
I am getting the following error in a peculiar fashion.
The point at which the driver is attempting to click on the element was not scrolled into the viewport.
The user story goes like this, if a selection is made in a check group, corresponding div with few fields will be enabled. Similarly for n-number of selection there will be n-number of DIVs. When i select only one option in the div, it works as expected but not for the multiple options.
i have read some stuffs and tried all the possible combination about the above said view port issue. My work around attempts and the outcomes are given below.
1) Tried with the Advanced interaction method. (Action class) - The same exception
2) Accessed with java-script executor- same exception
few more will be updated soon.
I have tried all the combination of locating mechanism. Everything works perfect and the element is in visible mode. But when i perform any operation on the second DIV values i am getting the above said exception.
what can be possibly done to get the element in working mode?
EDIT :
1.The DIV elements all are in view port and they all are accessible individually.
2. Div are enabled as per the check box selected
3.In a scenario, if we choose two check box, after a first selection you can edit the DIV and for the second selection the DIV will not be accessible.
4. both DIVs are identical with respect to the elements/attributes/properties of the elements.
5. When a Active div is edited no other div will be available in the UI.
For some reasons i was not able to produce the Reproducible code here.
i sorted out the problem. There was actually a frame for every DIV. these frames are just hidden after the edit and a fresh frame is opened every time, so when i access the second div i had to choose the latest frame.
i just polled for the number of frame and proceed with the latest one.
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/