Selenium Webdriver Modal not appearing when automated - java

I am writing automation code using Selenium Webdriver Java against an application for Point of Sales systems.
When the application opens up at first there is a modal dialog which appears for the user to select an item on. This modal appears no problem when testing manually. Until just recently it also appeared when running automation.
It no longer does. The behavior is different between manual and automated runs.
I'm running against Chrome and I've set the "disable-popup-blocking" option for the Chrome driver, but it doesn't seem to be helping.
The developers also have no idea what might have changed. I am at a loss and just looking for any thoughts about where to look for clues.
Thanks.

Let me try to address your query:
The behavior is different between manual and automated runs is factually incorrect statement until & unless you are controlling the WebDriver instance with arguments.
As you mentioned there is a modal dialog which significantly means that the code for the dialog is present in the DOM. Maybe it's within​ a frame which we have to find out.
"disable-popup-blocking" option for the Chrome - The purpose of this option have nothing to do with element present in the HTML DOM.
Amidst all the confusion, the best solution may be to take help of Selenium Builder & put an end to all guesses.
Let me know if this answers your question.

Related

How can I only allow the user to complete a reCAPTCHA using Selenium Webdriver?

I'm using Selenium WebDriver (in Java) to get some info from a site after logging in. This requires the user to complete a reCAPTCHA test. Everything before and after this is done automatically and the user does not need to see or do anything.
I would normally use a headless browser, but I need the GUI so that the user can manually complete the reCAPTCHA. Currently I am using ChromeDriver and WebDriverWait to wait until it is complete and then continue with my stuff. I am fine with this-- the user completes the test while everything else is automated. However, if the user does anything besides the test (new tabs, entering stuff in address bar), things get messed up. How can I prevent this?
Unfortunately, Captcha is intended to defeat automated programs like Selenium, and getting around CAPTCHAs is difficult by design. It does after all stand for "Completely Automated Public Turing test to tell Computers and Humans Apart". Typically, one has to configure the website in certain ways in order to disable the CAPTCHA for testing purposes. Though this will help automate the test in a smoother way, it compromises the security of the application. If your dev team allows this, then ask them to disable it for the purpose of running automated tests.
You will have to enter the CAPTCHA yourself while other fields will be filled automatically. This method only achieves automation to a certain point. Basically, the only way is using the WAIT command to tell the script to wait and complete the CAPTCHA manually.

Downloading Files with ChromeDriver

I have a project where I need to download an audio file in ChromeDriver. The behavior here is different from in regular Chrome, where if I visit the URL, it'll automatically start downloading a file. If I do the same thing manually in ChromeDriver, it will not download the file.
I've tried different configurations of the chrome options/preferences. I've also found options that worked with old versions of chrome, that no longer work anymore.
Here is one of the better resources I found, but it still didn't work, even with their updated blog post
https://dkage.wordpress.com/2012/03/10/mid-air-trick-make-selenium-download-files/
When I attempt to use his solution, my chromedriver abruptly crashes itself in a non chrome-esque way. It just disappears. Not "Something went wrong" page like you'd normally expect. I end up with Java not being able to find my Session, cause it stopped existing.
Has anyone been successful at downloading files through Selenium webdriver in Chrome? If I need to use another browser, I can.
I'm currently using Chrome Canary.
I have the same problem. One solution that might work is to use another library, that is able to operate outside of the browser. I found these stackoverflow post discussiong this issue:
https://sqa.stackexchange.com/questions/2197/how-to-download-a-file-using-seleniums-webdriver
it contains this blogpost wich gives you some sugestions.
https://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/
Window automation
The first approach smells like “brute force”: when searching the net for a solution to the problem, you easily end up with suggestions, to control the native window with some window automation software like AutoIt. Means you have to prepare AutoIt such, that it waits for any browser download dialog, the point at which Selenium is giving up, takes control of the window, saves the file, and closes the window. After that Selenium can continue as usual.
This might eventually work, but I found it to be techical overkill. And as it turned out, there was a much simpler solution to the problem.
Change the browsers default behaviour
The second possibility is to change the default behaviour of the browser. When clicking on a PDF for example, the browser should not open a dialog and ask the user what to do with the file, but rather save it without comments and questions in a predefined directory. To accomplish that, a file download has to be initiated manually, saved to disk and marked as the default behaviour for these file types from now on.
Well, that could work. You “only” have to assure that all developers, hudson instances, etc. share the same browser profile. And depending on the amount of different file types, that could be some manual work.
Direct download
Taking a step back, why do we want to download the file with Selenium in the first place? Wouldn’t it be much cooler, to download the file without Selenium, but rather with wget? You would have solved the second problem as you go. Seems a good idea, since wget is not only available for Linux but also for Windows.
Problem solved? Not quite: what about files, that are not freely accessible? What, when I first need to create some state with Selenium in order to access a generated file? The solution seems ok for public files, but is not applicable for all situations.

Selenium is breaking my page in IE11 when I set text

I made some Automation tests with Selenium working on chrome, but now when I tried them in IE11 I got this weird behaviour: I land in a Page with a Search Box and a Search Button, pretty standard, and when I either set(" ") or sendKeys(" ") to an input textbox, the page "moves" to the left as is it had broken, imagine the page in the center of the screen and suddenly the left margin would dissapear and the page would stretch to the left... Does anybody know what I'm talking about?
Any help please?
BTW I also tried doing some actions in other elements and they won't break the page, also clicking the textbox won't do the trick, it happens when I put text in it
Well, "sendKeys" is likely what we call a "native event" and so it depends highly on the implementation of the binary driver for IE. For example, Selenium only officially supports native events on Firefox up to version 31.0.6 and not versions 32+. IE11 is pretty new and also comes in different versions (since it auto-updates). So, if you need to do a sendKeys that is non-native (which is usually not necessary) then you can probably code one using a JavascriptExecutor object. Let us know if that works for you.
-- addendum --
The Selenium team would tell you that they didn't want to include the javascriptExecutor funtionality in Selenium, but it is scenarios like this where the executor capability shows its true value.

How to select proper Action for web target in Selenium IDE

I am new to Selenium IDE. As far as I know, when open Selenium IDE, you will notice that the red 'record macro' button is toggled. This means that selenium will attempt to record every action you make inside the browser. This is a problematic way of recording as we implicitly wait for actions to complete before moving on.
If I only let Selenium to record every actions without specifying extra actions, many test step will be failed with error message : Element not found. I was trying to add extra actions based on Selenium API, like waitForElementPresent, waitForSearch etc.
My question is: How do I know which extra action do I need to add for each web target? Any standard for it? Thanks!
I use webdriver but I am familiar with IDE and so far I know it depends on your application how you want to handle the tests. If your application uses ajax calls you might need to use some frequent waitForElementPresent or waitForSearch etc.. and Assertions also depend on the needs of your tests.
Now, the question is how do you know which extra step do you need to insert?
Ans. is you will know the necessity. Such as, if your test step depends on a previous ajax call to finish then you know there is a wait necessary and you know what to do. Not to mention, you can always insert extra steps and I am sure you already know that. And, there is no standard for using those. You adjust your tests depending on your necessity
you need to go through introduction to selenium ide or just think straight this way that if any action needs loading of page, you simple need to wait for element present and the perform click
click|target|
waitForElementPresent|target|
or if you need to store any value you can use
storeEval|target|value
also the variable name in the selenium ide is named followed by $variableName
enter can be performed as ${KEY_ENTER}
to verify any value we can use AssertValue or VerifyValue
the difference between assert and verify is that assert stops the execution of test case if the value is false whereas verify gives error and execute next statement.
these are few points to be noted in selenium ide.
hope this answer would help you!
You may want to try Implicit Wait addon for Selenium IDE. It will automatically call WaitForElementPresent before executing actions on that element (like clicks). This may save you some time.
Here is the link of Selenium API, all actions can be found here.

How to code an automated bot that can browse and do operations on a webpage. JAVA

need to code a bot that needs to do the following:
Go to a jsp page and search for something by:
writing something on a search box
clicking the search button(submit button)
clicking one of the the resulting buttons/links(same jsp page
with different output)
get the entire html of the new page(same jsp page with different
output)
The 4th one can be done with screen scraping and I do not think I need help with it. But I need some guidance to do the options from 1 to 3. Any links or just some keyword that will help me Google to learn about it will be appreciated. I plan to do this with java.
My suggestion is to use Selenium (http://docs.seleniumhq.org/download/).
Install Selenium IDE in your firefox, and it can record what you do on a website, store it into a script and reply it.
This video (http://www.youtube.com/watch?v=gsHyDIyA3dg) is gonna be helpful if you are a beginner.
And if you want to do it in Java, its easy, just export the scripts in Selenium IDE to JUnit Webdriver code.
Of course you can use Selenium Java webdriver in Java to write your program to operate on website directly.
Selenium automates browsers. That's it. What you do with that power is entirely up to you.
The above steps can be done by using selenium(which is a testing tool in java)
Even points 1 to 3 are screenscraping - you're figuring out (using either manual or automated means) what's there in the page and performing actions on them. You could try exploring the Apache HTTP Client for an easy way to run HTTP commands and get responses.
I hope you're doing this for legitimate means - screenscraping is almost always frowned upon if done without permission.

Categories