Answer a question

I'm getting my head around using c#/Selenium rather than JavaScript/Selenium. I'm having issues with Webdriver-manager and chromedriver.

Chromedriver is for v88 (Chrome Browser is also v88) yet when I run my test, it fails with ..

message: System.InvalidOperationException : session not created: This version of ChromeDriver only supports Chrome version 85 (SessionNotCreated)

I have tried using the old JS/Selenium technique from a command prompt webdriver-manager update followed by webdriver-manager startbut still get the same error.

Here's the code - which is experimental with real data removed....I know I'm missing something obvious...just can't see over my JS wall!!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using BAMCIS.Util.Concurrent;
using WebDriverManager.DriverConfigs.Impl;

namespace CFirstSharp
{


[TestFixture]
public class Chrome_test1
{
    private IWebDriver driver;
    public string homeURL;
   
    [Test(Description = "Login to PMS")]
    


    public void Login_is_on_home_page()
    {
        new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
        ChromeDriver driver = new ChromeDriver();


        homeURL = "https://<UL>/";
        driver.Navigate().GoToUrl(homeURL);
        WebDriverWait wait = new WebDriverWait(driver,
System.TimeSpan.FromSeconds(15));
       

        IWebElement siteID;
       
        siteID = driver.FindElement(By.XPath("//*[@id='winp_SiteID']"));
     
      siteID.SendKeys("<siteID>");


        IWebElement usrName;

        usrName = driver.FindElement(By.XPath("//*[@id='winp_UserID']"));

        usrName.SendKeys("<usrName>");


        IWebElement usrPass;

        usrPass = driver.FindElement(By.XPath("//*[@id='winp_Password']"));

        usrPass.SendKeys("<usrPass>");

        TimeUnit.SECONDS.Sleep(2);
        
       
        IWebElement logOn;

        logOn = driver.FindElement(By.XPath("//*[@id='btn_LogOn']"));

        logOn.Click();

        TimeUnit.SECONDS.Sleep(7);


        //IWebElement element =
        //driver.FindElement(By.XPath("//a[@href='/beta/login']"));
        //          Assert.AreEqual("Sign In", element.GetAttribute("text"));


    }


    [TearDown]
    public void TearDownTest()
    {
        driver.Close();
    }


    [SetUp]
    public void SetupTest()
    {
        homeURL = "https://<URL>/";
        driver = new ChromeDriver();

    }


}

Answers

Rather than using the methodologies of JS, I would suggest you adopt the C# package management to handle your drivers since you are now working with C#.

Assuming you are using Chrome version 88: https://www.nuget.org/packages/Selenium.WebDriver.ChromeDriver/88.0.4324.9600

Add that dependency to your project, on restore/build it will add the ChromeDriver.exe to your bin directory. Calling a new Chromedriver without specifying the path will either use the system properties that are set, or will look for a chromedriver.exe in the bin directory of your project, making this method a more fluid way to handle Driver management.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐