Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Click() method in C# is not returning, causing the test to hang. #5071

Closed
lukeis opened this issue Mar 4, 2016 · 38 comments
Closed

Click() method in C# is not returning, causing the test to hang. #5071

lukeis opened this issue Mar 4, 2016 · 38 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 4, 2016

Originally reported on Google Code with ID 5071

I have a Web Element (a link) that is correctly found on my page.

<a onclick="javascript:doPostDMS('en-us'); return false;" id="btnPentana" title="Post
To DMS" class="shelf-button lnkPostToDMS" href="javascript:__doPostBack('btnPentana','')"></a>

The problem I have is when I execute the click
1. The button is clicked
2, A new browser window is opened (this tells me I did actually click)

Problem: the click method doesn't return and the test hangs.

With the following code:

Console.WriteLine("Before");
Driver.FindElementById("btnPentana").Click();
Console.WriteLine("After");

I see the Before statement written to the console. I see the new window open (a result
of clicking the link). I do Not see the "After".

I expect to have the Click method return so I can continue on by switching to the new
window, etc.

Selenium version: selenium-server-standalone-2.29.0.jar
selenium-dotnet-2.29.1.zip
OS: Windows 7
Browser: Firefox 15.01, Chrome 20.0.1132.47 m
Browser version:


Reported by brianwork@brianandsherri.com on 2013-01-24 21:09:03

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

We need a reproducible scenario, that must include a sample page or a link to a public
site's page where the issue can be reproduced.

Reported by barancev on 2013-01-26 13:50:21

  • Status changed: NeedsClarification
  • Labels added: Browser-Firefox

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Here is the error that is thrown:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server
for URL http://localhost:4444/wd/hub/session/be8e564b-785a-4333-bd0f-e3ebc19efb1b/screenshot
timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out
Status: Timeout
   at System.Net.HttpWebRequest.GetResponse()
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line
124
   --- End of inner exception stack trace ---
   at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request)
in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\HttpCommandExecutor.cs:line
134
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,
Dictionary`2 parameters) in c:\Projects\WebDriver\trunk\dotnet\src\WebDriver\Remote\RemoteWebDriver.cs:line
836
   at DealerSocket.Automation.Common.ScreenshotRemoteWebDriver.GetScreenshot() in C:\WS\DSTeam\Main\Automation\Source\DealerSocket.Automation.Common\ScreenshotRemoteWebDriver.cs:line
24
   at DealerSocket.Automation.Common.ScreenshotRemoteWebDriver.GetScreenshotAsImage()
in C:\WS\DSTeam\Main\Automation\Source\DealerSocket.Automation.Common\ScreenshotRemoteWebDriver.cs:line
31
   at DealerSocket.Automation.Common.BaseTest.Execute(Uri remoteAdress, ICapabilities
capabilities, Action`1 action, Boolean deleteCookiesAtStart) in C:\WS\DSTeam\Main\Automation\Source\DealerSocket.Automation.Common\BaseTest.cs:line
49
   at DealerSocket.Automation.Common.BaseTest.Execute(ICapabilities capabilities, Action`1
action) in C:\WS\DSTeam\Main\Automation\Source\DealerSocket.Automation.Common\BaseTest.cs:line
22
   at DealerSocket.Automation.Web.Administrator.OEMDispositionTest.DMSPush(DesiredCapabilities
cap, String site) in C:\WS\DSTeam\Main\Automation\Source\DealerSocket.Automation.Web.Administrator\OEMDispositionTest.cs:line
387

I don't have a public site to provide.
Send me a message and maybe we can set up a skype session to help you get the information
necessary to reproduce it.

IE works.
Firefox and Chrome do not.
Selenium version: selenium-server-standalone-2.30.0.jar
selenium-dotnet-2.30.0.zip
OS: Windows 7

Reported by brianwork@brianandsherri.com on 2013-02-19 20:01:12

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

We are having the same issue and the site isn't public either.

In our case, there is an a tag with an onclick attribute inside of a frame.  I see
in the original post that the issue was with an a tag and an onclick attribute.  I
haven't tried other sites yet as I don't know of any public sites that match my test
criteria.  Hopefully someone can duplicate the issue on a public web site.

I have only tested this on Firefox.  Happens on Linux and Windows.

Thanks!

Reported by jason.r.paddock on 2013-03-11 23:51:46

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I've got the same issue for the following site:

Precondition: Register test user here - http://delivery.realeyesit.com/Account/Register
Steps to reproduce:
1. Open http://delivery.realeyesit.com/Account/LogOn
2. Input  User name
3. Input Password
4. Click LogOn button
throws the following exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server
for URL http://localhost:31571/session/54c9102d21d3e091b5a27d4543d758e7/element timed
out after 60 seconds. ---> System.Net.WebException: The operation has timed out

browser Chrome, webdriver 2.30.0, .Net

Reported by VoljaBes on 2013-03-27 11:03:45

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I have a similar issue with Microsoft Dynamics CRM.  When clicking on a button which
brings up a "Look up record' dialog, Chrome and FF will hang on the .Click() action.


IE 9.0, surprisingly, will return from the .Click() event and continue on (not sure
if that's indicative of anything).

Thanks,

Eric.

Reported by eric@thepelletiers.ca on 2013-04-05 15:16:30

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Any progress on this one please? I face this as well..

Reported by deepak.upl on 2013-05-03 10:05:29

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I faced this problem with our product as well.  We have a button that forces the server
to do a lot of back end work and when completed will return a page.  I think the problem
here is webdriver's wait for page to load method doesn't complete in time (.NET has
a default http timeout of 100 seconds, don't know why this is 60 seconds but it appears
to be the same).  A simple solution I have found which you may or may not want to do
is surround the click in a try/catch.  

Here is a sample:
try { driver.FindElement(By.Name("submitbtn")).Click(); }
catch (OpenQA.Selenium.WebDriverException) 
{ 
   //timed out as usual, let's just let it go since the page will still load and we
can move on
}

Reported by phase12 on 2013-05-03 15:30:31

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Any update on this?
I get this error consistently on one page of our web-app for IE8 on XP, with the latest
Selenium .Net webdriver version 2.33
For webdriver v2.21 I never get it on the same webpage.

The fail comes while clicking a tab on a page, which then performs a lot of Ajax calls.

The HTTP request to the remote WebDriver server for URL...timed out after 60 seconds
Has this timeout reduced since v2.21?

Thanks


Reported by tonywrenn on 2013-07-01 14:00:21

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I am also getting this error, just on a page that takes a long time to respond (2-3
minutes). I've set the following timeouts, but none of them are working:

driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMinutes(10));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));            
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMinutes(20));

Reported by morrisma258 on 2013-07-24 01:16:36

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I am having this issue with a dialog box which appears after clicking a button.

When I say element.click(); and goes for timed out. No control on appeared file upload
dialog box.

Reported by Santosh.vishwakrma on 2013-08-16 13:33:15

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I need to amend my previous statement.  I was able to solve my issue by adding the timeout
to my RemoteWebDriver object.  Here is some sample code:

driver = new RemoteWebDriver(new Uri(server_addr),capability,new TimeSpan(0,2,30));

This above code added the ability for operations to wait up to 2 minutes and 30 seconds
before timing out.  This solved my problem because after a click it generally took
about 2 minutes to return.



@Santosh, that sounds like a separate issue.  I don't think you use clicks for document
uploads, you just give it the file path with sendkeys.

Reported by phase12 on 2013-08-16 16:18:33

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I entered this issue almost a year ago, and I'm still experiencing it.

As stated in the issue, it still works in IE, but fails in Firefox and Chrome.
In my test, the object I'm clicking on causes a popup window to be displayed.
Handling popup windows is not an issue in general and I've handled them in many many
other tests.

While some people have mentioned the need to wait due to slow server response, or the
need for time to produce, this isn't the issue I'm experiencing.  Clicking the element
immediately produces the popup window, but the click event doesn't return.

Is anybody looking at this?
Can anybody provide a public site that is experiencing the same issue?

Brian

Reported by brianwork@brianandsherri.com on 2013-12-31 20:30:44

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Even i face same problem.
On click opens a new window, but click() doesnt return.

Reported by haisachin on 2014-01-16 10:17:19

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Please let me know what is the fix.

Reported by bantynigam on 2014-03-05 08:08:50

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

brianwork@brianandsherri.com: we still want a repro case

Reported by barancev on 2014-03-05 08:49:00

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I believe the issue is a showModalDialog is popping up.
Still not sure why it works in IE, but not FF or Chrome.

I don't have a public site to provide.
Send me a message and maybe we can set up a skype session to help you get the information
necessary to reproduce it.

Reported by brianwork@brianandsherri.com on 2014-03-05 23:50:12

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I think you should use the special contractor to extend the timeout value, for example
set it to 5 minutes:
_driver = new InternetExplorerDriver(driverPath, GetIeOption(),new TimeSpan(0,5,0));

Hope this helped!

Reported by xing.ma@outlook.com on 2014-04-28 18:46:49

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Even I am facing this issue. Any constructive solution, please?

Reported by patechetans on 2014-05-27 09:15:06

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

@patechetans: do you have a reproduction scenario?

Reported by barancev on 2014-05-27 09:24:07

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

public static void ManageTimeOut()
        {
            // Manage time out for the web page and controls load
            PageDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
            PageDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));

        }

Reported by mailKavitaKulkarni on 2014-06-12 12:25:40

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Hello Even I am facing the issue
I am trying to automated Microsoft crm dynamics using coded ui and selenium cross browser
components.
While I try to click on search hyperlink its throws the above error  for chrome.

Any resolution on this please??

Regards
Kamran

Reported by mkb114 on 2014-06-12 16:45:19

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Can anyone pls reply on this?
I have even tried try catch to supress that and proceed forward but in vain..

Reported by mkb114 on 2014-06-12 17:12:43

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

@mkb114: do you have a reproduction scenario?

Reported by barancev on 2014-06-12 20:38:02

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I have received response from Brian

public static void ClickAsync(this IWebElement element, RemoteWebDriver driver)
        {
            driver.ExecuteScript("var el=arguments[0]; setTimeout(function() { el.click();
}, 100);", element);
        }


Asynchronous click

Can anyone demosntrtae how to make call to this method
i am not able to pass the second parameter.

Reported by mkb114 on 2014-06-13 10:41:10

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Hello All,


I have set up the cross browser enviornment to test on chrome using coded ui.
I could not proceed with my execution on chromw as the control is not retured back
when it tries to click on some objects whihc have javascript.

Brian has suggested to use the below method for clciking
public static void ClickAsync(this IWebElement element, RemoteWebDriver driver)
        {
            driver.ExecuteScript("var el=arguments[0]; setTimeout(function() { el.click();
}, 100);", element);
        }


But unfortunately i am not able to make this piece of coded work .
can anyone please suggest what are the prequisite for this ?
any remoteweb driver server/client to be installed?
how to make coded ui fully working on chrome.

pls can some onesuggest?

Reported by mkb114 on 2014-06-13 14:52:07

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Send questions to the seleniu user group [1]

[1] https://groups.google.com/forum/#!forum/selenium-users

Reported by barancev on 2014-06-13 15:04:11

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

just add try catch block and it works 
try
            {
                IWebElement ele = driver.FindElement(By.Id("lookupimg"));
                ele.Click();
                Thread.Sleep(300);
            }
            catch (Exception e) {
                //Console.WriteLine(e);

            }
and give sleep and it works perfectly

Reported by kedar.matrix on 2014-06-21 12:10:43

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Closing the issue as there is no reproduction case provided.

Reported by barancev on 2014-06-21 12:21:36

  • Status changed: Invalid

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

I have the same problem and believe it is the problem with Selenium FindElement method.
The catch covering FindElement can never have a chance to throw exception because the
inner of FindElement throws out "The HTTP request to the remote WebDriver server for
URL....timed out" first.

Ihave implemented a method like this:
 public bool IsElementVisible(string expectedLocatorKey, params string[] dynamicContent)
        {
            IWebElement element;
            By by = ByLogic(expectedLocatorKey, dynamicContent);
            try
            {
                element = WebDriver.FindElement(by);               
                if (element == null)
                {
                    return false;
                }
                else
                {
                    try
                    {
                        if (element.Displayed && element.Enabled)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch
                    {
                        return false;
                    }
                }
            }
            catch (NoSuchElementException ex)
            {
                return false;
            }

        }

Reported by tam.nguyen@xero.com on 2014-09-01 07:04:07

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Exact same problem with IE webdriver version 2.42 C#.

Click works as expected, but does not return and http response times out after 60 seconds.

Don't understand what is so difficult to fix for over 18 months, add an option to either
wait for a http response or not, or option to lower that particular timeout to 1 or
0 or something.

post #4 provided a public site and prodcer and it was just ignored.

Reported by terence.rockerfella on 2014-09-07 15:14:15

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

@barancev@gmail.com

I am having same issue "selenium: Click() method in C# is not returning, causing the
test to hang" since last few days. It happens to just one link and works fine for other
links.

I am able to reproduce this issue on Chrome and Firefox browser. 
Do I need to upgrade webdriver?

Thanks

Reported by keshavkatoch on 2014-09-15 17:17:28

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

You know what to do, right? I've already requested this several times. Please provide
an executable scenario and a sample page to reproduce the issue.

By closing it I don't mind to say there is no issue. May be there is a bug in Selenium.
But the report is invalid because it is non-actionable.

Reported by barancev on 2014-09-15 17:29:04

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

@barancev, honestly sometimes dealing with you guys is such a joke. It has been over
a year. This is obviously a widespread, common, sporadic problem, test pages and code
scenarios have been provided in the above comments. I'll do it again. Honestly.

Sample page: 
http://www.huffingtonpost.com/

Executable scenario:
driver.FindElement(By.PartialLinkText("Entertainment")).Click();

There ya go. A note on the definition of "sporadic" - sporadic means that when you
try this scenario, it's usually going to work. If you run the scenario enough times,
eventually you'll get a timeout thrown.

Reported by writejohnemail on 2014-09-15 21:11:37

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Here is a sample code I tried to run:

IWebDriver driver = new FirefoxDriver();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
for (int i = 0; i < 100; i++)
{
  driver.Url = @"http://www.huffingtonpost.com/";
  driver.FindElement(By.PartialLinkText("ENTERTAINMENT")).Click();
}

and I can't get a failure.
(Note a difference "ENTERTAINMENT" vs "Entertainment" in your sample, your link opens
a new window on click, and 100 opened windows can actually cause browser failure, so
I decided to click a link that opens another page in the same window).

1) Is 100 iterations enough to reproduce the issue? How often do you obtain it?
2) Is this code complexity enough to reproduce the issue?
3) Do you use some specific capabilities and/or profile settings that can cause the
issue?

Reported by barancev on 2014-09-17 08:25:57

  • Status changed: NeedsClarification

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Even I am facing the same issue after clicking a link in IFrame. Once it clicked, the
test case will be hanged. I tried to click it in try catch block also, but did not
work. Please let me know if any one has found a solution for this issue.

Reported by ba.raghu on 2014-09-18 05:07:59

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Closing the issue as there is no reproduction case provided.

Reported by barancev on 2014-10-01 18:48:44

  • Status changed: Invalid

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Hello Team, 

I am also Facing similar issue with click() event. There it's clicking particular url
but unable to navigate to that page and after 60s of Timespan, its throwing an exception.
Please help me how this issue needs to solve. One option that i tried is using Javascriptclick()
method in Javascript executor. But is it proper to use javascript.click() method insted
of click()? 2. Should I try for option like getting latest webdriver.dll from selenium
website ? Please help me out.

Reported by jiteshgodwe009 on 2015-03-19 14:11:01

@lukeis
Copy link
Member Author

lukeis commented Mar 4, 2016

Reported by luke.semerau on 2015-09-17 18:16:38

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 4, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant