Element in View port issue [Peculiar] - java

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.

Related

Change driver focus between different page in single window in Selenium

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.

Selenium Webdriver: How to check if a ui element exists on specific screen regardless of if it currently visible/hittable

I'm using the AppiumDriver and MobileElement java packages (I'm writing in Kotlin) to UI test an iOS app that already has tests written using XCUITest.
I need a function that behaves the same as XCUIElement.exists() acts in XCUITest. This would be a function that returns true if the UIElement in question is present on the screen regardless of whether it is visible/clickable. An example of this is a UI element embedded in a scrollview that's out of sight (not scrolled to). It's on the page, but it is not visible nor is it hittable.
Right now I have a scrollview with UI elements out of sight, that the program will hang waiting for their visibility, until I manually scroll the scrollview to bring them into view, which at that point will pass the tests.
I can confirm that MobileElement.->
isDisplayed() (this behaves more like isHittable() than exists() from what I've seen)
isEnabled()
isSelected()
All do not do what I want, neither does anything along the lines of:
driver.findElements(By.xpath("value")).size() != 0
The above line seems to return true in the exact same cases as isDisplayed if I'm not mistaken.
EDIT: Some users have suggested that the elements may not exist yet due to lazy loading, and that being the reason why the
driver.findElements(By.xpath("value")).size() != 0
line does not work. In response to this I have added an image of the div representing the scrollview in the iOS app. The highlighted UI Element still cannot be found using until the user manually scrolls down to make it visible before the request times out.
driver.findElements(By.xpath("value")).size() != 0
Is the correct way to test if an element exists. This doesn't check viability, it just fetch all the elements currently in the DOM that match the locator. Even if you define implicit wait (if necessary) to the existence of the elements, nothing else.
To check the existance i.e. the presence of element regardless of the element being visible / hittable you have to induce WebDriverWait for the presenceOfElementLocated() and you can use the following Locator Strategy:
new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath("value"))).size() != 0

Unable to Access Elements on MS CRM 365

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.

Facing an issue while selecting drop down in Selenium webdriver

I am trying to select a drop down using selenium web driver, using this code:
WebElement admissionSource = driver.findElement(By.name("ABC"));
Select admissionSource_select= new Select(admissionSource);
Thread.sleep(10000);
Here, ABC is the value name attribute for that element.
It is selecting as expected, however once it moves to the next drop down just below that, it deselects the previous one.
Things I've tried:
1) After filling the next drop down, going back and filling the previous drop down again. However this second attempt selects the first drop down but deselects the next drop down(as is the application). Filling the next drop down again throws below exception:
org.openqa.selenium.StaleElementReferenceException: Element is no longer valid
2) Thread.sleep()
3) Implicit wait
4) Explicit wait
Please suggest on how to resolve this issue.
StaleElementException occurs when your referenced element is no more available or the element/page is refreshed. In your case, selecting from first dropdown refreshes/reloads your second dropdown. Hence, the StaleElementException occurs. To overcome this, after selecting from first dropdown, get the location of the second dropdown and select your element afresh each time.
This issue was coming because the in the 2nd dropdown, the options were dependent on the first one. So earlier i was just waiting for the dropdown box to get loaded. However in this scenario, even though the dropdown box had loaded but the dropdown options had not yet loaded for the 2nd drop down. Hence it was giving StaleElement Exception.
The way to tackle this is to use FluentDriver wait on the any (random) dropdown option and once it is loaded then only proceed further.
Between these two sentences from your question:
Select admissionSource_select= new Select(admissionSource);
Thread.sleep(10000);
Won't you need to do something like:
admissionSource_select.selectByVisibleText("Abc");
Where Abc is the name visible for that element.
You have just declared the drop-down element to be an instance of Select class. Is merely that sufficient? May be actually selecting the element was missing when you tried. You can try with adding above statement and then waiting while 2nd drop-down populates.

How to verify if Tab on Web Page is selected using Selenium RC..?

How to verify if Tab on Web Page is selected using Selenium RC
I wanted to one very simple thing. Does anyone know using selenium RC Python Client how I can know if a Tab is selected on web page?
By tab I mean the following examples from the following link-
http://esdi.excelsystems.com/wsexmp/DIVTAB.pgm?wsnum=00096
I have used focus(), isSomethingSelected(), isVisible() but didn't get the solution.
I need to verify that the specific tab is selected by default after webpage opens. Isn't there a method like is_tab_selected(tab_locator)??
please provide the clear solution pls..
I have used focus(), isSomethingSelected(), isVisible() but didn't get
the solution.
These methods use the common HTML element terminology.
focus() is for elements that are focused, meant as when you click a focusable element, it has a focus on it. To see what I mean, you can loop through the focusable elements on your page via pressing the Tab key repeatedly. This changes focus.
is_something_selected() is for selecatble <option> elements (which are the children of a <select> element)
is_visible() tells you whether an element is actually visible on the page or whether it is hidden via CSS.
Anyway, there's no is_tab_selected(tab_locator) method, because there's no such thing as a tab. In your case, your "tabs" are just simple clickable <a> elements which have a class attribute tab-active or tab-disabled based on their state.
Therefore, if you wanted, for example, to know whether the second tab is active, you would do
is_element_present("css=#tab2.tab-active")
This will return either true or false based on whether the tab is selected or not.
Or the other way around, if you wanted to know which tab is currently active, you would do:
get_attribute("css=.tab-active#id")
This will return the id of the selected tab.
You have to find a unique tag in your webpage. You can do
driver.findElement(By.xpath(".//tagname"))
If the above line doesn't throw any exception, you can confirm that you are located in your webpage.

Categories