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.
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 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
Hello: I am using Selenium/Java to grab a PDF from a website. The website does not generate them in advance, but only after I clink on a link. When I do, the web server goes away for a few minutes, and then comes back with the content.
I'm using Firefox, and its built-in PDF viewer. When I click on the download link from the main browser window, it opens another window to receive the PDF content. In a few minutes the child window is filled with the PDF content, and all I need to do is click a download button on the Firefox toolbar, and then press a Save button on the confimration dialog. I have done both of these things, successfully, sometimes.
My problem, sometimes occurs when I execute the code to click on the child window's download button...
WebElement element = driver.findElement(By.id("download"));
element.click();
Sometimes, it just doesn't work. The statement:
driver.findElement(By.id("download"))
...never throws an exception, so it appears to always be successful. Yet, the subsequent element.click() will often not produce the expected results.
I've thrown about 100 darts at this problem, but I can't seem to find one that produces consistent results. I've tried introducing delays, calling findElement several times, trying to use the driver on the child window in ways to confirm its connection to that window (all with positive return values), but nothing seems to help make element.click() on the darn download link successfull.
I have found Selenium to be a rock-solid solution, especially when working through the primary window...it never misses a beat, and I'm really quite impressed about that behavior. This is my first Selenium project, and I hoping someone that has used it a bit more, might have a suggestion for this particular problem.
It's hard to answer this question without additional information about how the child window is populated. If the child window is using javascript to add the button to the page and define its behavior (which is likely), then the element could be actually present on the page when you look for it (i.e. no error will be thrown), but it might not be active yet or prepared to be clicked.
It might be a good idea to look at the element definition in the source for the child page to get a better idea of how the button is coded. If you have access to the web developers who designed/implemented the button even better. If you can wait to perform the click action until the button is in the desired state, this should solve the problem.
Additionally if the page is coded using a dynamic framework like Angular, you might be better off using Protractor for testing, which is based off of Selenium, but which is aware of updates in the view as they are occurring.
I have very weird issue with some VBA code. The code is InternetExplorer automation and it's really simple: I just need to load page, enter credentials and click on the button on another page (after successful login).
But... My code is not working (but only on one of my machines on AWS). On my local machine this code works fine.
The weird thing is that it seams I have access only to the Document property of the first loaded page (where I need to enter login/password). I mean from MyBrowser.Document property I can see all INPUT fields when I load start page. But after successful login (the IE window is visible) I see same INPUT fields from MyBrowser.Document property! Also (as I said) I have no issues with this code on another maching.
IE Protected mode is disabled (this is IE 11). I think this is some kind of security issue but I can't locate it by myself...
Here is my code:
'MyBrowser is IE instanse
'Here I'm loading start page and input login/password
'Next the browser show me another page where I need to click a button
'But Debug messages show me input fields for the first Form!
Application.Wait (Now + TimeValue("0:00:05"))
Do
DoEvents
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
For Each myHTML_Element In HTMLDoc.getElementsByTagName("INPUT")
If myHTML_Element.Type = "submit" And myHTML_Element.Name = "BUTTONNEWJOBS" Then myHTML_Element.Click: Exit For
Debug.Print myHTML_Element.Name
Next
UPDATE
I don't know why but my browser object is always Busy that's why I get old page HTML. I tried to .Stop it but with no luck.
I don't have answer for IE11 automation, just a hint for a path you may choose to walk.
Another Stack Overflow question Getting source of a page after it's rendered in a templating engine? provides some browser automation options.
One of the mentioned tool has currently broken support for IE11 due to a IE11 behavior change, see http://docs.seleniumhq.org/about/platforms.jsp#browsers. The blocking issue has some configuration hints you may find useful.
In my opinion Internet Explorer was ALWAYS the least reliable tool both from the point of view of rendering compatibility, programmability and even the automation problems accross different versions. And although it had improved over the years Internet Explorer is still better to be avoided (from programmer's point of view). Today it is luckily not the only tool available.
So if you just need to get the work done, there are other browsers or browser-like tools that you can use.
If you MUST use IE then you should get your answer at the Internet Explorer Dev Center → Community → Developer forums
EDIT (after comments)
By the symptoms in your question it looks like the browser object is busy because of some dialog box (perhaps a security prompt) is being show to the user. Some links from Google that may help:
required IE configuration from the selenium browser automation engine - https://code.google.com/p/selenium/wiki/InternetExplorerDriver
how to disable Internet Explorer Enhanced Security Configuration - http://4sysops.com/archives/four-ways-to-disable-internet-explorer-enhanced-security-configuration-ie-esc/
Internet Explorer Security Zones and Compatibility View - https://help.blackboard.com/en-us/Learn/9.1_SP_14/Administrator/030_Browser_Support/030_Browser_Support_IE_Issue
set of dialogs that can be manipulated by the iMacros Internet Explorer automation toolkit - http://wiki.imacros.net/Browser_Automation#Dialog_Manager
Rewriting ~1000 lines of code to use another automation interface (or browser) and asking for help at the Microsoft's Internet Explorer Dev Center are IMO still valid options
Based on your following statement
I see same INPUT fields from MyBrowser.Document property!
it would seem that the page hasn't fully loaded. Perhaps it is loading data via AJAX and clicking the submit button shows the exact same page (which would explain why you were seeing the same INPUT fields) while waiting for a response from the server.
An easy way to test this is to wait for a longer period of time (e.g. 30 seconds) and ignoring the value of the browser ReadyState. However a better way would be looping until you find a element on the successful page that isn't on the first page, with a possible timeout of maybe 30 seconds.
I've used Selenium to do some automation and ran into similar problems and had to resort to using Implicit Waits but I'm not sure if VBA as such a feature (as I don't know VBA)
If I use IE I can visit the website I want and click the 'Next' button and life is good. If I open that same website using the webBrowser control and click the 'Next button I get a javascript error message.
I'm not doing anything in the code to manipulate the website. My goal, eventually, is to have some level of automation; but at this point, I get the javascript error and a pop-up and it screws everything else.
I can hide the JS error from popping up; by setting 'WebBrowser1.ScriptErrorsSuppressed = True' but the page isn't working because of the error.
The client script might be assuming a full browser is present and trying to access part of the browser outside the Document Object Model (DOM) of the page. For example, maybe the client script is trying to display something on the browser's status bar, or trying to modify a toolbar which isn't available in the WebBrowserControl. There could be numerous similar reasons.
If you do not have write-access to the web page in question to try fixing it, then play with WebBrowser Control properties such as ScriptErrorsSuppressed and ObjectForScripting
Try setting WebBrowser1 Silent property to true.
Actually, you are receiving this problem because when you run your site in IE8 or IE9 on your normal internet explorer desktop app, you are getting either IE8 or IE( rendering, depending on which you have installed. However, with the webbrowser control, unless you take the effort to change soem settings in the registry, the default rendering engine used by the webbrowser control is IE7 (if u have 7, 8 or 9 installed) and IE4 (if you have 4, 5 or 6 installed).
This is why you are having the problem, if you want help changing the rendering engine version for your webbrowser control, do a google search as there are many examples on SO, and i have provided this answer in some of my previous posts on this tag/topic. feel free to search or ask me.
Let me know how you go.