How best should I interact with Flash from Selenium Java WebDriver - java

I am aware a bunch of similar questions such as (Interact flash elements using WebDriver) have been asked in the past however it is still not clear how best to interact with a Flash Element on a page in association with Selenium's Java WebDriver.
By default I know it doesnt support Flash, so I use it to log onto the site which is fine. Now I need to interact with a flash element as seen on this page :
http://store.nike.com/us/en_us/product/free-tr-4-id/?piid=34979&pbid=517639039
I want to be able to pick a shoe size from the Flash on the left hand side of the page, and then click the add to cart button.
Can anybody who has achieved this please offer their guidance and opinion on the best way. I have tried https://code.google.com/p/flash-selenium/ however this appears to be old, or not compatible with the new Java WebDriver.

The answer to your question is: No, there is no way you can interact with Flash from/using Selenium WebDriver. Full stop.
I know there are heaps of developers out there need to automated Flash. But this has never been a part of the Selenium project and it will never be added into. You might want to have a wander around Selenium Users group.
For projects like flash-selenium and flex-ui-selenium, they are not part of the Selenium project but created by third party, which means they can easily be discontinued due to various reasons. If you have decided to use them, you might end up developing the project itself instead of using it. Furthermore, I'm not aware of such projects compatible with Selenium WebDriver anyway.
One other possible solution might be using Sikuli, which is not a Flash automation tool though. It should support automating Flash with its unique image comparison technology. But once again, this has nothing to do with Selenium in any way.

There is a massive misconception that webdriver cannot interact with flash elements.The answer is YES you can interact with flash elements embedded inside html if you can locate the xy coordinates you can interact using selenium ACTION class like so..
Actions Action = new Actions(driver);
WebElement e = driver.findElements(By.cssSelector("button"));
Action.moveToElement(e).clickAndHold().perform();
Action.release().perform();

Related

Java - Go to new url in new window/tab

I want to be able to use Java to tell it to go to X url when X browser is open/running (my lingo is terrible). (Firefox/Chrome/IE is already up, and I want it to go from the default page to let's say Twitter.)
Most of the solutions are using java.awt.Desktop to launch native browser with a url in it, but that isn't useful if I want to change the url later on. (Already on Twitter-Home Page, but want to go to Twitter-Contact Us afterwards.)
The other solutions I've seen involve using Selenium WebDriver, but I also need to eventually learn how to basically force the Java to read a long list of URLs off an excel and simply verify that url isn't dead, and then do this on the Native Android browser, for example. So the Selenium might not be the right choice. Granted, you can also tell me this is an awesome choice for this too if it truly is. I haven't really been exploring Selenium.
Sorry for asking such a basic question. Company wants QA Automation without training/hiring an Automation QA. My end goal (aside not getting canned), is to see if I can get a bunch of urls to load on specific browsers. I can sort of (praying) be able to do stuff with it afterwards.
A simple trick would be to create an add-on( if you know javascript ) which will be quite similar in chrome and firefox (for IE I have no idea in my days it needed BHO) and send websocket commands from java to your addon. But this needs a java websocket server running where your addon will connect when the browser opens. Rest of communication can be carried upon the protocol lines of your requirements.
There are multiple parts to your question.
Read urls from excel.
Use Apache POI to do the same. Selenium code can use the same.
Check that the urls are not dead.
Use any java http client, (apache) to do that without even opening a browser. If the link is dead, it will be dead for all the browser.
Open the links in a multiple browsers.
Selenium is perfect for this. I am assuming that after the page is loaded you have way of validating that the page is correct. Selenium is very powerful here.
Target native android browser too.
I do not know of much difference between this and the previous question unless you are also testing site display based on browser size. The browser is more or less the same as chrome with webkit rendering engine.

Selenium click chrome physical buttons like menu, left, right navigation, bookmarks

I'm working on a some automation work, as per my requirement I need to click on Chrome Physical buttons like left nav, right nav, bookmarks, menu etc. I can do with shortcuts but my requirement is to click on browser buttons. Any ideas would be helpful. Thanks in advance.
As per your question you want to click on Chrome Physical buttons like left navigation, right navigation, bookmarks, menu etc.
But if you look into the documentation in Selenium Home Page it clearly mentions that :
The entire suite of tools provided by Selenium results in a rich set of testing functions specifically geared to the needs of testing of web applications. These operations allow many options for locating UI elements and comparing expected test results against actual application behavior.
So factually Selenium by design interacts with the HTML DOM and the WebElements located in the DOM Tree
Now the desired controls e.g. left navigation, right navigation, bookmarks, menu are out of the DOM. Hence you cannot mock the click on those controls.
However all the Selenium Language Binding Art provides a handfull of methods to achieve the same result. Here are a few from the Selenium Python Binding Art :
Maximize : To maximize the browser window.
driver.maximize_window()
Minimize : To minimize the browser window.
driver.minimize_window()
Close : To close the browser window.
driver.close()
Quit : To close the browser window gracefully.
driver.quit()
Refresh : To refresh the url.
driver.refresh()
Forward : To move forward.
driver.forward()
Back : To move backwards.
driver.back()
And of-coarse Get : To invoke an url.
driver.get('http://google.com/')
There are functions for this that is built-in:
driver.forward()
driver.back()
https://selenium-python.readthedocs.io/navigating.html#navigation-history-and-location
It doesn't appear that selenium can interact with the Bookmark, but let me check some more.
This can't be done with selenium webdriver and I think also not with the standalone selenium server. Selenium only allows to interact with the DOM.
The only way to achieve what you want to do is to use an automation tool that actually runs directly in the OS that you use. Java can be used to write such a program.
I would however recommend to not go this route. Instead try to convince whoever is responsible for your requirements to re-think and allow to use other means of achieving back and forward actions.

Scraping flash using HtmlUnit or other java tool

I am using HtmlUnit to scrap date from a site but after login all the data is displayed using adobe flash player as swf object, I don't know any way to scrap data from such page.
Is there any way to extract data from flash page, If yes please help me out, either using HtmlUnit or any other java tool.
thanks.
There is no way that you can interact with Flash applet using HtmlUnit. You can try with selenium; I never used it, but it looks like there are plugins that enable flash communication like flash selenium
Personally, I think the only way to test user interfaces, when they have such pitfalls, is to hire a tester human being (a good one), and teach the developers to deeply test the gui every time they alter it.
Seems am not too late, there i answered to my question. what all you need to do is
Create your own browser instant
Inject "stockwave flash" plugin
Instantiate htmlunit with new browser instance.
Hope it will help you.

Selenium RC not able to work with downloads popup window

I am new to the selenium RC. I have been working in eclipse to run a simple junit test case to run and download flashplayer from adobe.com.
But the selenium RC is not able to click or even recognise the downloads pop up window. I have been seeing several suggestions in google search but still I am not able to do it.
I have been trying to get the window ID or name of the pop up window to work with it, but still I am not able to do it. I have copied the major function of my code here down below:
public void testPopup() throws Exception
{
selenium.open("http://get.adobe.com/");
selenium.open("/flashplayer/");
selenium.click("id=buttonDownload");
String ids[]=selenium.getAllWindowIds();
for(int i=0;i<ids.length;i++)
System.out.println(ids[i]);
String[] windownames=selenium.getAllWindowNames();
for(int i=0;i<windownames.length;i++)
System.out.println(windownames[i]);
String feedWinId = selenium.getEval("{var windowId; for(var x in selenium.browserbot.openedWindows ) {windowId=x;} }");
System.out.println(feedWinId);
selenium.chooseOkOnNextConfirmation();
selenium.waitForPageToLoad("30000");
}
It will be great if someone can help me out with this.
Thanks
The short answer: you can't.
The longer, but still disappointing answer:
You can't, because no current Selenium implementation supports it. The Selenium people know about it, it's actually nr. 13 in most wanted features in Selenium right now
Selenium RC will never have it because of its technical limitations (It's pure JavaScript. And pure JavaScript can't download and save files.) and it has been deprecated over a year ago. Selenium WebDriver ... well, maybe, in the future. The various things you can try instead:
Rethink whether you really need to download the file. Isn't is ok just to assert that the file exists and can be downloaded by making a HTTP request and seeing that the answer was 200 OK?
Can't you download the file using pure Java after you get it's URL via Selenium? I personally think this is the best way to go.
If you're using WebDriver, there is a great tool for downloading files!
If you're using Firefox, you can set up a clean testing profile that will be configured so that it will download every clicked file into some specified folder. There are addons out there that can help you with it, too. I'm not sure whether Selenium RC supports usign a precreated profile, but Selenium WebDriver definitely does.
If you're using one given browser to do your tests, you can figure out how to download a file "blindly" by pressing buttons blindly. The Robot class can help you with that. You just click the file and then blindly press Enter or whatever keys to download your file into the right place. There is also AutoIt framework which a lot people use for this task.
You can not automate system generate pop-up by using selenium.
For that you have shift over Autoit with selenium.
With the help of this you can records your activities on download pop-up

Firefox = Render the Web-Page to an image file

what is the current "state of art" to render a webpage in firefox into an image file (saved on disk). I want to implement something like "browsershots.org"
1.) Does firefox provide some API to interact with it?
2.) Does the new Canvas (HTML5) Element help here?
The programming language does not matter.
If you know any more information about this topic or a concrete solution, please help.
Uupdate: Yes, the Idea is to do this programatically, only using Technologies "within" Firefox. Further Ideal requirements: Multithreaded (allow rendering of several Websites in parallel on one machine)
Thanks very much, Markus
update: Yes, the Idea is to do this
programatically, only using
Technologies "within" Firefox.
See: https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas#Rendering_Web_Content_Into_A_Canvas
Mozilla's canvas is extended with the
drawWindow() method. This method draws
a snapshot of the contents of a DOM
window into the canvas.
Sounds good, but note that:
This feature is only available for
code running with Chrome privileges.
It is not allowed in normal HTML
pages. Read why.
Why reinvent the wheel?
Fireshot does exactly that: https://addons.mozilla.org/en-US/firefox/addon/fireshot/
Even if you want to implement that yourself, looking at that add-on might help.
Selenium RC is a good choice.
It allows you to control Firefox (and other browsers) using Java (for instance).
For example:
http://seleniumexamples.com/blog/examples/capturing-screenshots-from-remote-selenium-rc/

Categories

Resources