0

C#

.Net 4.5

VS 2013

NUnit 3.2.1

Webdriver and Webdriver.Support 2.53

So my issue is I am trying navigating to ebay's sandbox login page and login. This seems simple enough but I am struggling to get the page to fully load before giving me a System.Net.WebException timeout error.

Here is the link I am trying to go to https://signin.sandbox.ebay.com/

And Here is what my code looks like that is doing this.

var EbaySandboxPage = new EbaySandboxLoginPageModel(Driver);
Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(200));
Driver.Navigate().GoToUrl(EbaySandboxLoginPageModel.sandboxUrl);

And here is the exception that is getting thrown every time I try this in Firefox.

Test Name:  VerifyItemsSold
Test FullName: POMAuctivaTest.TestSuite.PostSaleTestSuite<FirefoxDriver>.VerifyItemsSold
Test Source:    c:\git\POMAuctivaTest\POMAuctivaTest.TestSuite\PostSaleTestSuite.cs : line 204
Test Outcome:   Failed
Test Duration:  0:00:00.0000001

Result Message: 
OneTimeSetUp: OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:7055/hub/session/80efbcbe-841d-4a53-a422-5e7498a0438b/element timed out after 60 seconds.
----> System.Net.WebException : The operation has timed out

So my question is how to I change the System.Net.WebRequest.Timeout property? I am not using an instance of webrequest. I guess webdriver is but I would imagine there is a way for me to change this value. As you can see I have already upped the SetPageLoadTimeout() value to exceed 2 min. Which in my manual testing has been more than enough.

Here was my attempt at @Buaban's solution although mine was still throwing the exception.

        Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(120));
        try
        {
            Driver.Navigate().GoToUrl(EbaySandboxLoginPageModel.sandboxUrl);
        }
        catch (WebDriverException)
        {

        }
        EbaySandboxPage.WaitForElementVisible(Driver, EbaySandboxLoginPageModel.usernameFieldSelector); 

Here is what the WaitForElementVisible() method looks like.

    public void WaitForElementVisible(IWebDriver driver, By element)
    {
        try
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
            wait.Until(ExpectedConditions.ElementIsVisible(element));
        }
        catch (WebDriverTimeoutException)
        {
            TakeScreenshot(Driver);
            Console.Write("Test failed trying to wait for this element " + element.ToString() + " to be visible ");
        }
    }

Here is the definition of the usernameFieldSelector

public static By usernameFieldSelector = By.CssSelector("#userid");

1
  • There's a dead resource on the page. That's why you are getting the time-out. Instead of increasing the time-out, you should reduce it to 10 seconds and wait for one of the targeted element to be present on the page. Commented Apr 21, 2016 at 23:40

2 Answers 2

1

So thank your @Florent and @Buaban, with your help I was able to figure out a solution to this. Ill post it here but award the answer to your Buaban as I am not sure I would have been able to get to this as quickly without your help.

        Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));
        try
        {
            Driver.Navigate().GoToUrl(@"https://signin.sandbox.ebay.com/");
        }
        catch (Exception)
        {
            System.Diagnostics.Debug.WriteLine("Some resources are dead!");
        }
        var attempts = 0;
        while (attempts < 2)
        {
            try
            {
                IWait<IWebDriver> wait = new DefaultWait<IWebDriver>(Driver);
                wait.Timeout = TimeSpan.FromSeconds(20);
                wait.PollingInterval = TimeSpan.FromMilliseconds(300);
                wait.Until(d => d.FindElements(By.XPath("//span[text()='SIGN IN']")).Count > 0);
                break;
            }
            catch (WebDriverException)
            {
                attempts++;
            }
        } 
Sign up to request clarification or add additional context in comments.

Comments

0

As Florent B. mentioned in comment, some page resources are dead. You have to ignore the exception then wait for an element on the page. See example below:

Driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(30));
try
{
    Driver.Navigate().GoToUrl(@"https://signin.sandbox.ebay.com/");
}
catch (Exception)
{
    System.Diagnostics.Debug.WriteLine("Some resources are dead!");
}
IWait<IWebDriver> wait = new DefaultWait<IWebDriver>(Driver);
wait.Timeout = TimeSpan.FromSeconds(10);
wait.PollingInterval = TimeSpan.FromMilliseconds(300);
wait.Until(d => d.FindElements(By.XPath("//span[text()='SIGN IN']")).Count > 0);

System.Diagnostics.Debug.WriteLine("SIGN IN textbox is loaded");

4 Comments

Well this works! thank you, but I would like to understand this issue a little better. You and Florent B said page resources were 'dead' what exactly does that mean and how does this happen?
@JoshuaBurns Technically, webdriver will automatically wait until all resources (js files, images,, ...) are loaded. But it seems there are something wrong with ebay website so some resources are timeout. This causes webdriver to be timeout. So you have to catch the timeout exception and continue your script.
And second I tried to implement your solution using methods I have already built in my project and was still running into the exception I am editing my question to include the approach I tried modeled off your solution. If you could take a look and explain why yours work and mine didn't it would be much appreciated.
Well I thought this solution worked. I have been testing it this morning. I saw it work twice but I have since have had no luck. I have your code pasted in my project but your wait.Until() line is still throwing the exception. Results are very mixed. I am seeing the work and then the subsequent run it will fail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.