So I am writing a class in eclipse using selenium and autoitx4java libraries, now I have been having an issue that I believe is selenium specific (meaning having nothing to do with autoIt).
Basically when I arrive at the splash page for the website I am attempting to test, the first thing I do is find the element for the login page via XPath, and click on it using the click() method. This is supposed to open up a certificate window.
Once the click() method runs a certificate window comes up, however, for some reason the selenium test does not keep running lines of code. Instead it pauses at the line the click function was executed. The code looks a bit like this:
WebElement login = driver.findElement(By.xpath("example_xpath"));
login.click();
// login.sendKeys(Keys.ENTER);
System.out.println("login clicked");
Class.selectCert();
(Where "Class" is just a class created for this specific test.)
So when the code is run in Selenium, the line "login clicked" is never printed out. As you can see, the alternate sendKeys(Keys.ENTER) function has been tried. When I used this function, literally nothing happened, and the code continued as if that line of code did not exist.
Note: When I highlight the element and manually press ENTER, the certificate window actually pops up.
This is where things get weird. When I remove the line for the click function, and replace it with a pause() function which gives me ample time to click on the element manually. The code runs perfectly fine, the "login clicked" is printed out, and the certificate window is handled by the autoIt code I have in the selectCert() function.
I have tried clicking on different elements on the screen, and so far this bug only occurs when clicking on elements that have an xpath with /img at the end of it. Not sure if that helps at all... Any help would be appreciated!
Related
My scenario which produces the question goes something like below:
I enter a webpage via normal means, next I press on a button, to start a HTML5 application on this webpage, this application is inside an iFrame. On application start I'm being prompted to either turn the sound on or off. At this point there are two possible outcomes:
1. When I answer this prompt manually, new buttons appear in the application window, as expected.
2. When I answer this prompt through automation via Appium, new buttons do not appear.
Now to the question:
To answer the prompt I use the click() method from Selenium. Is it possible that this click() is not considered to be executed by a human and therefore doesn't trigger necessary things? And since I don't have access to the source of the application can I force the Selenium click() to look exactly like a human click?
Here is the code I use to execute the mentioned click:
//Application loading up, hence the sleep
Thread.sleep(5000);
AppiumTestBase.getDriver().switchTo().frame("e_iframe");
Thread.sleep(5000);
WebElement soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
AppiumTestBase.getStandardWaitTime().until(elementToBeClickable(soundOff));
soundOff.click();
The program is able to find and switch in to the iFrame, there are no cross-origin issues either. The AppiumTestBase is just there for initializing the driver, setup capabilities etc. I also tried clicking the element via Actions and JavaScript, but there was no change in behavior.
In C# a workaround I've found to actually take control of the mouse and move it/click with it is to use "Microsoft.VisualStudio.TestTools.UITesting" for the Keyboard/Mouse libraries. From there, you can tell it "Mouse.Click(new Point(X, Y));"and it will move your mouse to that location and click.
Sample Code:
using Microsoft.VisualStudio.TestTools.UITesting;
var soundOff = AppiumTestBase.getDriver().findElement(By.id("soundOff"));
Mouse.Click(new Point(soundOff.Bounds.X, soundOff.Bounds.Y));
I am automating a web page, and I am having lots of issues in clicking in a element, so I implemented this
try {
element.click();
} catch (WebDriverException e) {
clickJS(element);
}
clickJS is a method I wrote to click using javascript approach, it usually works, however I am having issues when the expression to click does not throw any exception, but in the future steps will fail because it did nothing. Is there a way for assert a click has 'worked' even though it did not throw any exception.
ps: Iam sure the webelement is clickable
PS: I am using chrome webdriver
There's no generic way to determine if a click was successful because a click could do just about anything... navigate to another page, click a checkbox, dynamically load another part of the page, etc.
In general, I would say that this is not the right approach if you are trying to automate a customer scenario. For example, you attempt a click but didn't anticipate some dialog popping up. Your normal click would throw an exception that another element would receive the click but your JS click would succeed. You shouldn't want that click to succeed because a user couldn't click that element without dealing with the dialog first. This may cause a strange failure down the road that will be hard to trace. Do a "normal" click each time. As you run the script, you will find intermittent failures. Investigate them and find solutions, e.g. wait for some dialog to close because 1 in 10 times it closes slowly and so on. In the end, you will have a more robust suite.
You can check whether your click is actually happened or not in some of the scenarios.
Ex: most of the case click will lead to some change in the UI that might be UI change,HTML source code change or some text might change.if nothing is changing after your click then the click itself is no use.
Solution: take a snap shot before ur click and take a snapshot after click then compare both images if u found any difference then ur click performed successfully else not.
I am using protractor v4.0.9 and node v6.8.1 (although I have also tested this issue on 4.6). I have a test that runs through a series of button clicks to get to a form. The code looks something like this:
browser.get('http://someurl');
// App select button
element(by.id('btn-select-app')).click();
// portal select
element(by.id('row-test-portal')).click();
// provisioning form button
element(by.id('btn-provisioning-form')).click();
This is then followed by a function that iterates through the form and fills it out. If I run the test from start to finish (including the function that fills out the form) it will fail when it tries to start filling out the form because it is on the wrong page - that is, even though the terminal is telling me it executed the click on the provisioning button, the form did not load.
If I shorten the test and run it only with the commands you see in the block above, it passes.
When I run it in debug mode I can execute the "element(by.id('btn-provisioning-form')).click();", but it doesn't appear to actually do anything - it will tell me it executed the the click, but the form does not appear on the page - I am still on the previous page. Note that the above test contains another button click prior to the click on the provisioning form button and that appears to work normally.
I have gone so far as to use different locators for the button including xpath and css but the nothing will get me to the provisioning form.
Button code
<div class="col-md-1">
<button id="btn-provisioning-form" ng-show="foo()"
class="btn btn-success glyphicon etc" ng-click="blah()"
aria-label="Provision" popover="Provision" popover-trigger="mouseenter">+</button>
</div>
Some other notes - I have managed to replicate the test using Selenium IDE and when I run that test from the Selenium IDE UI, it is able to click the button and get to the form. It looks like this issue is just being seen when I use protractor.
TL;DR : Protractor is telling me it clicked the button, but the button click isn't causing any change to the page. When I manually click the button outside of protractor, it works just fine. Why is this happening?
Instead of normal protractor click , try clicking through JavaScript code.
Several of my vendor's require me to place orders thru their websites. I have automated the process by clicking on a button in my order processing program. My program will open the default browser (now IE 9 after my previous computer died), navigate to the vendor's website order page, fill out the information fields, and then click the form submit button.
this.oIE.Document.all.ctl00_MainContent_Login1_LoginButton.click()
or
this.oIE.Document.getElementById("ctl00_MainContent_Login1_LoginButton").click()
The problem appears to occur only when the button has an "onclick" value.
In IE8, the click() event executes the onclick code. In IE9, the click event returns a generic object. It does not fire the onclick code.
I have tried x.FireEvent("click"), but this returns an object as well. It appears that IE9 DOM onclick values cannot be executed by external programs.
My program works fine on IE8 (I use Chrome, IE, FireFox with different settings and logins, so changing the default browser is not really an option. Also, some of my vendors demand that I use IE as their sites are broken on the other browsers.)
Any advice on a permanent fix for this would be appreciated.
I could have written your question verbatim, and have been fighting this for as long as you have.
Stupid, stupid problem: The click() function now requires a parameter: click(1)
w = this.oIE.Document
z = w.getElementById("btn-header-input-signin")
z.click(1)
Haven't thoroughly tested this, but it works on the US Postal Service login page.
The function that the button click calls will presumably have the same name on each browser. Can you call that function instead?
Simulating the button click seems an unnecessary step. Also, have you tried jQuery? Libraries like that try to smooth away browser differences.
I'm confused about the difference between the Click and ClickAt commands in selenium. Where can I use the ClickAt command?
Here are what Selenium IDE says about those two commands :
click(locator) Arguments:
locator : an element locator
Clicks on a link, button, checkbox or
radio button. If the click action
causes a new page to load (like a link
usually does), call waitForPageToLoad.
And :
clickAt(locator, coordString) Arguments:
locator : an element locator
coordString : specifies the x,y position (i.e. - 10,20) of the mouse
event relative to the element returned
by the locator.
Clicks on a link, button, checkbox or
radio button. If the click action
causes a new page to load (like a link
usually does), call waitForPageToLoad.
click is used when you just want to "click" on an element, like a button, a link, ...
And clickAt is used when you want to "click" on a position designated by mouse coordinates.
I suppose the second one can be useful for some "rich" applications -- I've actually never used it... On the other hand, I use click like all the time.
If you have a page with form elements, links, buttons, and stuff like that, you'll probably generally use click : it's way easier to find an element using it's id or classname than having to find it's position in pixels on the page ^^
I noticed some differences between click() and clickAt() when testing a ExtJS app.
For example, if I try to click a tab in a Ext.TabPanel, click() command does not work, although I provide it with an correct xpath, and clickAt() works fine.
Code looks like this:
click("//li[#id='tab-panel-id__second-tab-id']/a[2]/em/span/span")
doesn't work, but
clickAt("//li[#id='tab-panel-id__second-tab-id']/a[2]/em/span/span","0,0")
works.
Notice that coordinates are (0,0)
I can't figure out why this happens...
I'm testing a GWT application and it seems like I have to use clickAt if I want to click on a node in a tree widget.
Be careful when testing clickAt. Sometimes double clicking the command will cause it to show up red. You will change the line to try other alternatives but nothing will work. But then run your script and the clickAt line will be fine with whatever you type in.
There is a dojo widget at our application which only works with clickAt("//span[#id='mastheadIconBar']/span[1]/span/span","0,0").
Don't know why, but only click("//span[#id='mastheadIconBar']/span[1]/span/span") does not work.