Why is there no "scroll down/up" functionality with Selenium Webdriver? - selenium

Every implementation of scrolling I have seen requires executing Javascript (scrollTop, scrollTo for example), rather than an available method in Selenium Webdriver to perform this action. Since Webdriver is designed to perform the same interactions in a browser that a user might take, why is this not found anywhere?
I understand that using Webdriver to interact with an element in the DOM saves from having to scroll elements, however some libraries like ReactVirtualized are designed to only render visible rows, making automation that much more difficult.

Are you using Capybara (as your question is tagged) or selenium-webdriver directly?
If using Capybara then you want the scroll_to method - https://www.rubydoc.info/gems/capybara/Capybara/Node/Element#scroll_to-instance_method - which was recently added.
If you're using selenium-webdriver directly, it's because for a long time there was insistence by some of the writers of the WebDriver spec that scrolling wasn't necessary. That insistence changed at the last WebDriver spec meeting but details of how scrolling should work haven't actually been added to the spec yet.

Related

Does AEM support selenium automatic testing on editor or author mode?

I have been using Selenium to test the user interface of my AEM site on preview mode. It was done without any technical problem. However, when I try to run selenium test on editor or author mode, such as clicking on a web component to open component dialog, my webdriver is unable to get the web element and throw an exception calledĀ org.openqa.selenium.elementnotinteractableexception.
I have tried to solution on StackOverflow, but none of the solution is helpful for what I am doing.
For example, I have something like this on selenium in Java:
WebElement button =
driver.findElement(
By.cssSelector(
"div[data-path='/content/components-examples/library/button/jcr:content/root/responsivegrid/test/component/button']"));
button.click();
The element Not interactable exception is thrown once I try to click on it by using "button.click()".
However, if I do the same thing on Preview mode, nothing will happen but the button getting clicked, and no exception will be thrown.
Does AEM support selenium automatic testing on editor or author mode? If it does, how can I overcome this issue?
I wont suggest doing automation testing on AEM author because the components will keep on changing and it will be very difficult to get a particular selector.
For example if you are selecting the button using the cssSelector with data-path, what if the button is changed, few more buttons are added before the particular button you are targeting.
About supporting selenium, I am not sure but for unit testing mockito is mostly used. Hope this helps.

Finding xpath of shadow dom elements with robot framework

I'm writing automated UI tests using Robot Framework with python. I'm testing a Polymer application that uses the shadow dom Robot's standard libraries don't seem to be able to locate elements in the shadow dom using xpath.
I've been sorting through selenium's repo/overflow/internets and polymer's repo/overflow/internets and haven't found the intersection of a solution for using robot with python (the selenium workaround isn't that graceful either). I was hoping someone had run into this issue with this specific framework that might be willing to share a solution (or note that there's not one).
Test Case
Wait Until Page Contains Element xpath=(//html/body/some-root-shadow-dom-element/input)
This of course results in an error because the shadow dom is not put into the main document of the DOM tree.
Open the browser console and type this into the console:
dom:document.querySelector("apply-widget").shadowRoot.querySelectorAll("div)
Make sure to hit enter after so it will be ran.

Is Selenium 2.0 waiting for element / page to load?

I heard that Selenium 2.0. is waiting for element or page to load by default, so there is no longer need to write specific methods like 'waitForElementToLoad' after calling click method.
Is it true? If yes, why can't I find it anywhere in documentation? I constantly find some posts like this, where it's only mentioned:
Selenium - don't wait until all elements are presented
Please advice where can I find any proof of that, what methods are waiting for element to load, and from which version it is implemented?
I am using Selenium 2.0 with Chrome Driver.
Thank you.
As in docs (http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp) :
"An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance."
So, you need to set it manually, ie need to wait elements to load. By default Selenium doesn't wait, as written above.
Also here: https://sqa.stackexchange.com/questions/2606/what-is-seleniums-default-timeout-for-page-loading is mentioned that "The default WebDriver setting for timeouts is never"

Getting unexpected results using selenium waitForNotVisible

I have some selenium based tests a feature where an item is deselected on the page, which causes that element to be removed from the page. Because it is ajax based I do a click for the deselect action, and then wait for the element to no longer be on the page before moving on. the basic flow is
click(TargetElement)
if(isElementPresent(targetElement)){
waitForNotVisible(targetElement)
}
...
This seems to work 100% of the time when run against a local selenium server instance, but when run against the selenium grid I have set up, it always times out on waitforNotVisible (in both cases, the conditional is always met).
Originally when this was failing, I didn't have the conditional and I thought that would clear it up, but it didn't. Maybe my expectations for waitForNotVisible are not correct, but I wonder why this would be working locally and not against the grid. All of my other tests seem to work fine via both methods.
And yes, I am using selenium 1; at the moment moving to selenium2/Webdriver is not an option in the short term, so please don't suggest using webdriver as a solution. At the moment I'm most interested in understanding why this would fail as-is.

Selenium clicking a button

I am trying out selenium for the 1st time and I have a quick question. When I call the click() method on a WebElement, I noticed that it is a void type method. So does the HtmlUnitDriver hold the updated page that is rendered after the click() happens?
Yes. The WebDriver interface is controlling the browser, however it's still the browser (in your case, HtmlUnit) that does most of the work and remembers the state of teh page etc.
Therefore, WebDriver as such doesn't really have a state (an overly simplified statement, but true for your purpose). When you send a click() command, it performs it in the browser, than waits for the browser to complete its job (load the new page), then again waits for your commands on the new page.
WebDriver always operates on what the browser currently has.
I can see from your question that you are using HtmlUnitDriver. JavaScript is disabled in this driver by default (for explanation click here). This driver uses the Rhino JavaScript engine and is not used in any of the popular browsers. This might explain why the actions you are trying work fine in Firefox but not in Selenium.
You could try enabling JavaScript in HtmlUnit as follows:
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);
But instead I would recommend using FirefoxDriver.
WebDriver driver = new FirefoxDriver();
This should emulate the behavior you're seeing when you navigate through the webpages yourself.