NUnit error due to System.Net.Sockets.SocketException [Selenium WebDriver]

I am trying to iterate through 3 divs in the outer div and then get the text from the h1 element from each of the inner divs.

My HTML looks like this:

<div view-role="outerList">
    <div class="question">
        <div class="question-header"></div>
        <div class="question-container">
            <div class="question-view">
                <h1 class="question-title">
                    What is your name?
                </h1>
            </div>
        </div>
    </div>    
    <div class="question">
        <div class="question-header"></div>
        <div class="question-container">
            <div class="question-view">
                <h1 class="question-title">
                    What is your favorite color?
                </h1>
            </div>
        </div>
    </div>    
    <div class="question">
        <div class="question-header"></div>
        <div class="question-container">
            <div class="question-view">
                <h1 question-heading class="question-title">
                    How old are you?
                </h1>
            </div>
        </div>
    </div>       
</div>

      

My C # code looks like this:

foreach (IWebElement question in all_questions)
            {               
                string question_name = question.FindElement(By.CssSelector("h1.question-title")).Text;
                Console.WriteLine(question_name);
            }

      

In my case, the question is each of the divs that have a question class. So there are 3 of them.

NUnit error with NoSuchElementException

OpenQA.Selenium.NoSuchElementException : no such element
  (Session info: chrome=42.0.2311.152)
  (Driver info: chromedriver=2.12.301325 (962dea43ddd90e7e4224a03fa3c36a421281abb7),platform=Windows NT 6.1 SP1 x86_64)

      

However, when I debugged my C # test and entered my line that was throwing an error in the nearest window, I was able to get the actual item. However, before that it was also printing out a socket exception.

    question.FindElement(By.CssSelector("h1.question-title"));
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
{OpenQA.Selenium.Remote.RemoteWebElement}
    [OpenQA.Selenium.Remote.RemoteWebElement]: {OpenQA.Selenium.Remote.RemoteWebElement}
    Displayed: true
    Enabled: true
    Location: {X = 902 Y = 390}
    Selected: false
    Size: {Width = 420 Height = 53}
    TagName: "h1"
    Text: "What is your name?"

      

I don't understand why I am getting a socket exception, even though I can actually retrieve the item.

Additional information: Here is my driver instance:

private IWebDriver driver;
driver = new ChromeDriver();

      

+3


source to share





All Articles