I hit another bump
webBrowser1.Document.GetElementById("submit_button").InvokeMember("click");
When it runs the button moves in the browser but it still do not work, I have to click the button twice that runs the code then it works
I tried using
webBrowser1.Document.GetElementById("submit_button").Focus();
webBrowser1.Document.GetElementById("submit_button").InvokeMember("click");
still not working
I think I need some kind of double click instead of only clicking once
As long as you are sure you have the proper ID for the element then the issue may just be that the "click" member is being invoked before the page has loaded.
Try this to be sure the document is loaded:
if (webBrowser1.ReadyState==WebBrowserReadyState.Complete)
webBrowser1.Document.GetElementById("submit_button").InvokeMember("click");
If it is a double click that you need, possibly try invoking the click twice with a sleep in between of a couple seconds? It is not the cleanest method though..
Related
So this is similar to Click() method will not always work but there are several vital differences:
Not a timing issue because I repeatedly try to click it until success
No exception is thrown, just nothing happens
Using a JS click on the same element works - executor.executeScript("arguments[0].click();", element);
Using button.SendKeys(Keys.Return) instead works.
Displayed: true and Enabled: true
Only button.Click() doesn't work. I've stopped the application at a breakpoint and am testing it via the Immediate Window right now. I can see how Click() has no effect and doesn't throw an exception, but javascript click() and SendKeys() work.
Some additional info:
I'm using InternetExplorerDriver on IE11
I'm running the tests on Windows Server 2012 through Remote Desktop
It happens only intermittently. I remember switching Alt+Tab while the tests are running whenever it's happened but I don't know if this is the reason.
Any idea what is happening?
Edit: I noticed at one point that the first click pushes down the button (visibly) but it doesn't get click. The second click succeeds, however. Earlier Click() did not succeed, no matter how many times I executed it.
Edit 2: OK, now I've nailed it - if I click on the browser window, then I click to Visual Studio, then the first Click() doesn't work. Subsequent clicks all work, even if VS is still focused. Switching from VS to notepad and then to VS does not trigger it, only switching to IE and then back to VS.
It's as if it's not the problem that IE doesn't have focus, it's about having it and then losing it, then the next Click() will fail.
In my case the contol was partially overlapped with another div, and the webDriver clicked in the middle of control but hitted the div. Could you please check maybe it is your case.
in a .net windows forms project which has 100s of forms, and all those forms has countless custom made controls with base classes involved, its very difficult for me to know where a particular button is, i mean whats the form name which I'm looking at while i'm running the application, and where exactly is the button click event, in code, of the button that I just clicked. Is there a debugging feature in Visual Studio, which would just break the execution for me to the line where the click happened. Can I tell VS to break at which ever Click event comes next?
(running visual studio 2012/13 these days).
thanks.
Just before you click the button in the program do this:
Go to visual studio and pause the program. Just press the pause button.
Then press F11 (Step Into).
Now press the button in the program, and you should be taken into the event handler.
For web projects, the technique suggested by Jakob Olsen will not really work, because you have no active thread in between the calls, and hence no thread to resume upon the next action. However what worked for me was:
Find some code (any code in your app) you know for sure it gets executed and set a breakpoint
Trigger this breakpoint, use SHIFT-F11 to step out until you're out of all methods
Now do the action of which you don't know what code is executed, and it will break
I can suggest partial solution.
If your click events are named like "Button_Click", open Breakpoints windows while in debug and create New breakpoint.
Click OK and you will see list of functions. Check them and click OK. On every function that you have selected will be created a breakpoint.
I am using __doPostback of a button control and it will take some time to complete the db operations. I am using it in an update panel and I am getting an issue from IE that it will say
Stop running this script.
May I know what is the issue ?
I think it may be due to __doPostBack. Previously it is direclty calling the Click Event. Thanks in advance.
Check your User Agent string. This same thing happened to me one time and I realized it was because I was testing out some pages as "googlebot". The JavaScript that is generated depends on knowing what the user agent is.
From http://support.mozilla.com/tiki-view_forum_thread.php?locale=tr&comments_parentId=160492&forumId=1:
To reset your user agent string type about:config into the location
bar and press enter. This brings up a list of preferences. Enter
general.useragent into the filter box, this should show a few
preferences (probably 4 of them). If any have the status user set,
right-click on the preference and choose Reset
Avoiding the 'Script taking too long' (all browsers have some form or another of this) message in browsers is relatively simple. You just have to make sure the browser knows you have not created an endless loop or recursion. And the easiest way to do is is to just give the browser a breather in between long running tasks.
have a look at this solution
http://www.picnet.com.au/blogs/Guido/post/2010/03/04/How-to-prevent-Stop-running-this-script-message-in-browsers
Here's the scenario:
Platform: Windows
IDE: Microsoft Visual Studio 2008
Language: C#
.NET framework: 3.5
My application contains 2 buttons - "Load Data" and "Stop Loading Data" and a multi-line textbox. Upon clicking "Load Data" button some data starts getting loaded in the textbox. To prevent the user clicking on the "Load Data" button multiple times, I have disabled that button once it is clicked. When the entire data gets loaded in the textbox then the "Load Data" button gets activated again. On the other hand on clicking "Stop Loading Data" button the loading of data is stopped (if user wishes to stop it before loading the entire content).
As stated earlier, to prevent the user clicking on the "Load Data" button multiple times, I have disabled that button with the intention that user can only click on "Stop Loading Data" button or else wait for the entire data to be loaded in the textbox. I implemented this. At first glance it seemed to work well. But while testing I found that even though the "Load Data" button is disabled, if the user clicks on that button, although nothing happens at that instant but as soon as the entire data gets loaded and the button becomes enabled again, that click made during the disabled state is found to be executed. As if the program was recording the keystrokes and mouse clicks and waiting for the button to become active again. But there are no such keystrokes or mouse-clicks recording facility in my program. What is causing such an activity? How can I prevent such behavior?
Thanks.
One option would be to work with a reentrancy sentinel:
You could define an int field (initialize with 0) and update it via Interlocked.Increment on entering the method and only proceed if it is 1. At the end just do a Interlocked.Decrement.
To make it visible for the user you can disable the button at the beginning of execution and enable it when the execution is finished...
BTW: long-running tasks should be done async (via a separate thread for example)...
if you make your call a synchronous one, it will lock up the entire page until loading finishes.
Otherwise you'd be just doing the method you've already tried, i'd like to see your code for the disabled state, because something tells me you just made it appear to be disabled, and it was still a functional button
Check out this post:
http://www.codeguru.com/forum/showthread.php?t=480279
My first thought was removing the event handler and rebinding it at the end of the click event. This thread suggests using a BackgroundWorker and making it async.
I bet that you can't even move the form until data is loaded, and you also can't stop loading data. The problem is that the whole form freezes until loading is done. You must move the loading part in separate thread.
Well, another silution again:
On begin load simply hide a load button and in place of it (say) show a progress bar. On finish of loading or on stop loading click make load button visible again. In this case you avoid "chain clicks" management you complains about.
Or manage one button. First it is load, on click, instead, becomes stop load. Solution like this you would find often in mobile environment, considering the limited screen space. But I think it can be applied to desktop with great sucess too. Why not?
I'm developing an addon for IE8+.
Main function:
- when I click the toolbar, it will display a box inside every single page, ex: google.com, bing.com, codeproject.com... by using execScript to execute jQuery.
Therefore, what Im doing is run javascript in the current page.
Everything has done except when that page perform an Pop-up, it doesnt work anymore.
I click the toolbar, nothing happen, but when I look at the pop-up, surprise! has the box which im trying to display. So, I think the current tab and the popup of its is running the same process.
I have change registry key TabProcGrowth to 20, to make sure every single tab run by its own process, but maybe it not work with popup.
sr for my bad english, any suggestion is welcome.
Thanks in advance.
update:
I have changed the way to develop my addon, so I change my question, too. (But any suggestion for the 1st question still very useful for me).
My new question still mention the "execScript" problem.
HOW to execute javascript with every individual tab of IE browser with TabProcGrowth = 0. I need this value set to 0 because I have the timer to request to the server every interval1 (ex: 60s). So if there are more than one processes of IE, the addon will send multi request to server at the sametime.
In my situation now, I set TabProcGrowth to 0. Open IE, open some tabs. Click the toolbar at the newest tab, it works, ofcourse!. But when I click toolbar at the old one, nothing happen. The script still be execute but it takes effect on the newest tab.
It's the big problem for me, resolve this problem, you guys save my life.