Selenium Integration: No definition for method "Single"

Ask general questions here.
xeronar
Posts: 28
Joined: Mon May 22, 2017 8:19 pm

Selenium Integration: No definition for method "Single"

Post by xeronar » Fri Jun 30, 2017 10:59 am

Ranorex version: 7.1

Hi all,

after I've watched the webinar about integrating Selenium into Ranorex, I tried the same thing as being shown in the webinar:

Code: Select all

using OpenQA.Selenium;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

namespace SeleniumWebDriverExample
{
    /// <summary>
    /// Description of SeleniumCode.
    /// </summary>
    [TestModule("250606FA-C3C6-423B-9A79-112C83FD2EDC", ModuleType.UserCode, 1)]
    public class SeleniumCode : ITestModule
    {
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public SeleniumCode()
        {
            // Do not delete - a parameterless constructor is required!
        }

        /// <summary>
        /// Performs the playback of actions in this module.
        /// </summary>
        /// <remarks>You should not call this method directl instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
            var webDriverEndpoint = Host.Local.TryGetAsWebDriverEndpoint();
            
            if(webDriverEndpoint == null)
            {
            	throw new InvalidOperationException("Endpoint not found!");
            }
            
            var existingDriver = webDriverEndpoint.WebDrivers.Single(wd => wd.Title.startsWith("Ranorex"));
        }
    }
}
But for some reason i got the following error message:

Code: Select all

'System.Collections.Generic.IEnumerable<OpenQA.Selenium.IWebDriver>' does not contain a definition for 'Single' and no extension method 'Single' accepting a first argument of type 'System.Collections.Generic.IEnumerable<OpenQA.Selenium.IWebDriver>' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\nk.maiman80\Documents\Ranorex\RanorexStudio Projects\SeleniumWebDriverExample\SeleniumWebDriverExample\SeleniumCode.cs:57,63
Is there something missing?

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: Selenium Integration: No definition for method "Single"

Post by Vega » Fri Jun 30, 2017 10:15 pm

Hi, it looks like you are missing a using statement from the sample project provided on the release notes page:

using System.Linq;

Try adding that and it should now build properly.

xeronar
Posts: 28
Joined: Mon May 22, 2017 8:19 pm

Re: Selenium Integration: No definition for method "Single"

Post by xeronar » Mon Jul 03, 2017 12:35 pm

Hi, thanks a lot, it works now. I'm quite new to C# so I'm not that familiar with the common resp. mandatory libraries yet :D

User avatar
Vega
Posts: 109
Joined: Mon Jul 11, 2016 2:15 pm

Re: Selenium Integration: No definition for method "Single"

Post by Vega » Mon Jul 03, 2017 2:06 pm

No problem! It was actually an easy thing to miss if you are just quickly glancing