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.
Related
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.
I am working on a little app for myself. I am trying to get a list of links from a site. The site is for example: http://kinox.to/Stream/Prison_Break.html
If you hover over the big window in the middle that says kinox.to best online, it show the link that I want in the bottom left. The problem is if I look at the html file I can't find the link anywhere. I guess it has to do something with the site using JavaScript or Ajax.
Is it possible to somehow get the link using JSoup or are there any other Java libraries that could help me?
I did not look closely into the page you try to load, but here is what I think the problem may be: The link is loaded/generated dynamically via JavaScript. Jsoup does not run JavaScript, so therefore you can't find the link in the html.
Two possible solutions:
1) Use something like selenium webdriver to access the content. The Java bindings allow to remote control a real browser which should have no problems loading the page and running all scripts within. Solution 1 is simple to program, but runs slowly. It may depend on an extern browser program which must be installed on the machine. An alternative to webdriver is the JavaFx webkit engine in case you are on java 8.
2) Analyse the traffic and the JavaScript on the page and find out where the link comes from. This may take a bit of time to find out, but when you succeed you can use Jsoup to get all the data you need. This solution should run much faster than solution 1.
One solution and probably the easiest would be to use Selenium:
WebDriver driver = new FirefoxDriver();
driver.get("http://kinox.to/Stream/Prison_Break.html");
String mylink = driver.findElement(By.cssSelector("#AjaxStream > a")).getText();
I was wondering what the differences are between calling the click() method of the WebElement versus finding the element by id and firing the click event with JavaScript.
Just to be clear in the first method I call the .click() of an instance of WebElement:
myWebElement.click();
The second technique is:
((JavascriptExecutor)driver).executeScript("document.getElementById('myElementID').click()");
I'm interested in knowing all the differences between these two techniques for clicking web elements, and also advantages and disadvantages of each.
Webdriver utilizes a browser's native support for mapping the DOM element to WebElement object using id/xpath etc.
The JavascriptExecutor.executeScript executes an external script in the context of the currently selected browser window. (similar to an augmented browsing tool like grease monkey, if you ever used),
and in case the script returns any DOM element its converted into WebElement object.
One can also say, the click simulated by WebDriver on a browser is similar to what actual user do as compared to one invoked using javascript.
In reality, with WebDriver not all the events can be automated flawlessly with all the web browsers, in fact with different versions of the same Web browser also. (i.e. different version of IE, FF etc behave differently). Still WebDriver is the near best tool available for this.
Once (~4 years back) on a certain version of IE we observed that we can't send right click or may be hover mouse on generated menu links, so we used js to simulate that, which performed very much browser independent way. so you can now conclude what executing external javascript can be good for.
Also, there are automated web testing frameworks which use javascript for everything instead of browser's native support. e.g. :http://en.wikipedia.org/wiki/Sahi_%28software%29
Ref:
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/JavascriptExecutor.html#executeScript%28java.lang.String,%20java.lang.Object...%29
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/WebDriver.html#findElement%28org.openqa.selenium.By%29
Those kind of tests are E2E (end to end) not BDD.
First one – is executed now, to take next action you must write some function that will delay execution for e.g download new data from server.
The second code return promise – http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html – „Schedules a command to click on this element.” – you can use then callback to run next action.
We have a website which has a wijmo grid in it. I am attempting to test this website. In IE the grid is drawn, yet when I go into the "Developer Tools", the grid is not actually there. This makes running Selenium tests very difficult as Selenium cannot find it either.
Has anyone run into this before? If so, how do I successfully run my tests?
The grid will be part of the DOM and you should be able to select it successfully with the correct path using Selenium.
I believe it is the tools that are misleading and are simply not updating when the DOM changes.
I would try checking another browser, for example Google Chrome (F12 in Windows). In my experience the IE Developer Tools are not as powerful or feature rich as the Chrome tools. The Chrome tools do update the DOM when elements are manipulated.
It looks like it is working now. The Developer had a pre-loader which was causing the problem. Once that was disabled it is now able to find the elements.
I am working in Selenium RC. Can anyone please let me know how to write xpath for button in Selenium (Java)?
You should develop the script in the Selenium IDE (download) before porting it to Selenium RC. In Selenium IDE, when you click anything on the webpage, it should automatically generate some kind of selector for the element you clicked. Then, once you've recorded all the events, you Format it in whatever language you're using, and then you copy and paste it to your Selenium RC code.
But the Recorder Javascript isn't foolproof (e.g. if you click on a div that causes some XMLHttpRequest or setTimeout, it won't be recorded). Or, the click may be recorded but you may not like the selector that Selenium chooses for the element. In either case, you'll have to write your own selector based on the DOM structure. To see the DOM structure, open Firebug if you're in Firefox (F12), or open the Inspector if you're on Chrome (Ctrl-Shift-J) Fortunately, Selenium understands a bunch of selector syntaxes, so you can use CSS selectors if you don't know XPath.
If you do decide to use XPath, you'll have to learn it first. I haven't found any good tutorials (and I'm not a fan of w3schools). But feel free to use a bookmarklet to test XPaths that I wrote. You'll probably end up with something like //button[.="text on button"], or //input[#value="text on button"].
You can find button Xpath by using Firebug which is an add-on for Firefox and as above answer Selenium IDE is also another, easier option to find.