How can I press on a button without a form using Goutte? - behat

I am trying to use mink and behat to test out my application. One of the tests requires me to press on a button, but that button is tied to a javascript event. Not an actual form.
When I run the test I keep getting the following error message.
The selected node does not have a form ancestor.
Is there way I can emulate the press button without having a form?
Any help would be really appreciated. Thanks

Goutte (and Guzzle) will not parse / run the javascript contained within an http response. As a result you can test for the existence of the button, but not if any events associated with the button actually fire. To test for the javascript based events you will have to use a different mink-driver. I refer you to Documentation on in Browser Testing and mink documentation on available drivers.
A

Related

Tooltip covers the button so I get org.openqa.selenium.ElementClickInterceptedException

I'm using Selenium for integration testing of our web app, and it's been working great up until I got far enough down the sidebar menu. Suddently the Create test would fail with org.openqa.selenium.ElementClickInterceptedException: element click intercepted. Other element would receive the click:
The error was very sporadic - order of tests would affect which test class failed - but finally I figured out the reason is that the tooltip from the most recently clicked menu option covers the button I'm trying to click. Not really sure why sending input to form elements (using WebElement:sendKeys() and org.openqa.selenium.support.ui.Select) does not count as moving the mouse away.
Is there a way to make Selenium work around this, or do we have to turn off tooltips in the test version (for obvious reasons I don't like the idea of running our tests on a custom version of the web app)?

Click not working on combo-box down arrow button karate UI testing

I tried clicking on down arrow button for a Combo Box (Select is not available. Its a React JS application and once I click on arrow button only list shows selection items) using below karate command but click not happened in application and no error displayed. [The same xpath worked in selenium click command,and showing unique item on Inspect search]
And waitFor("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
And click("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
Note: Then I tried below command
And assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
and got error
javascript evaluation failed: assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists, :1:19 Expected , but found root
assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
It would really help us if you follow this process, it is simple and should not take much time for you to give us a small snippet of static HTML (or you can mix react if really needed).
https://github.com/intuit/karate/tree/master/examples/ui-test
EDIT: you also seem to have mis-matched single and double-quotes in your code.
Also note that you should be able to fire a JS event or click by using the script() API. See this example: https://github.com/intuit/karate/tree/master/karate-core#script
So this is an alternate approach to be able to overcome any tricky situation that comes up.

Is the Selenium click() recognized as human or automation?

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));

IE9 Automation of Button Click

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.

Automation of DOH Robot tests interrumped by Pop-up message

In order to automate DOH tests during our build process, I use Selenium RC to launch different browsers (IE and Firefox) on a server placed on a different domain than the build machine. Each browser is directed to our runTests.html in order to start DOH.
Sometimes, when a test that uses doh.robot starts, the following message is shown:
"DOH has detected that the current web page is attempting to access DOH, but belongs to a different domain than the one you agreed to let DOH automate. If you did not intend to start a new DOH test by visiting this Web page, press Cancel now and leave the Web page"
but since these tests are unattended it just sits there waiting for someone to click OK, and Selenium times out (in IE 8 it seems like the pop-up disappears automatically but the robot does nothing afterward).
As I said, it doesn't always happen. After you click OK on the Pop-up, the message will stop showing, and the message can go away for several sessions, but then it will show again in which seems to be an arbitrary way.
Does anyone knows a way to prevent this pop-up from showing?
This is probably not the correct way to do it, but in util/doh/robot/DOHRobot.java, you may be able to modify the code to not check that or always simulate pressing "OK". I haven't tried it myself, but I may also need to do that for some of our automated testing.
When the DOH robot is initialized, it first tries to click in the upper left corner of the page you are trying to test. If you obscure this div (you can see it with firebug), then the message will pop up. I think the problem is that your page isn't always loading up quick enough.
It is somewhat of a challenge to fix this. I haven't used DOH in awhile, but I don't think there is any way you can use a setTimeout to fix this. (You can try using setTimeout on the doh.run command, but it might be the case that the DOH robot clicks that div before parsing any doh commands.)
Another thing you might be able to do is add a sort of "wait" command to Selenium, or whatever shell command you are using to fire up the system.