0

使用 selenium 包后,它给了我 chromedriver.exe 的此错误不存在。请让我知道是什么问题。我也按照对话框中的说明进行了操作,但问题仍然存在!下面是我的 c# 代码和 G1ANT Studio 的一些图像。

C#代码:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using G1ANT.Language;

using OpenQA.Selenium;

using OpenQA.Selenium.Chrome;

using OpenQA.Selenium.Firefox;

namespace G1ANT.Addon.YouTube
{
    [Command(Name = "youtube.open", Tooltip = "It opens youtube in a web browser")]
    class OpenCommand : Command
    {
        public OpenCommand(AbstractScripter scripter) : base(scripter)
        {

        }
        public class Arguments : CommandArguments
        {
            [Argument(Name = "browser", Required = true, Tooltip = "Type of browser; For Chrome, type: chrome; For Firefox, type: firefox")]
            public TextStructure Browser { get; set; } = new TextStructure();
        }
        public void Execute(Arguments argument)
        {
            if(argument.Browser.Value == "chrome")
            {
                IWebDriver driver = new ChromeDriver("C:/Users/Krishna/source/repos/G1ANT.Addon.YouTube/packages/Selenium.Chrome.WebDriver.83.0.0/driver/chromedriver");
                driver.Navigate().GoToUrl(@"https://www.youtube.com/");
            }
            else if(argument.Browser.Value == "firefox")
            {
                IWebDriver driver = new FirefoxDriver("C:/Users/Krishna/source/repos/G1ANT.Addon.YouTube/packages/Selenium.Firefox.WebDriver.0.26.0/driver/geckodriver");
                driver.Navigate().GoToUrl(@"https://www.youtube.com/");
            }
            else
            {
                RobotMessageBox.Show("Wrong input" + argument.Browser.Value + "\n For Chrome, type: chrome; For Firefox, type: firefox");
            }
        }
    }
}

G1ANT Studio 中的错误:

它说我在 G1ANT Studio 中运行“youtube.open browser chrome”命令后 chromedriver.exe 不存在

4

1 回答 1

0

此链接的答案是其中之一,它有助于解决此错误!

https://stackoverflow.com/a/51608925/13725510

其次,我修改了路径,请参考问题中的代码和以下代码(错误解决),其中提到路径的行:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using G1ANT.Language;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;

namespace G1ANT.Addon.YouTube
{
    [Command(Name = "youtube.open", Tooltip = "It opens youtube in a web browser")]
    class OpenCommand : Command
    {
        public OpenCommand(AbstractScripter scripter) : base(scripter)
        {

        }
        public class Arguments : CommandArguments
        {
            [Argument(Name = "browser", Required = true, Tooltip = "Type of browser; For Chrome, type: chrome; For Firefox, type: firefox")]
            public TextStructure Browser { get; set; } = new TextStructure();
        }
        public void Execute(Arguments argument)
        {
            if(argument.Browser.Value == "chrome")
            {
                IWebDriver driver = new ChromeDriver("C:/Users/Krishna/source/repos/G1ANT.Addon.YouTube/packages/Selenium.Chrome.WebDriver.83.0.0/driver");
                driver.Navigate().GoToUrl(@"https://www.youtube.com/");
            }
            else if(argument.Browser.Value == "firefox")
            {
                IWebDriver driver = new FirefoxDriver("C:/Users/Krishna/source/repos/G1ANT.Addon.YouTube/packages/Selenium.Firefox.WebDriver.0.26.0/driver");
                driver.Navigate().GoToUrl(@"https://www.youtube.com/");
            }
            else
            {
                RobotMessageBox.Show("Wrong input: " + argument.Browser.Value + "\n For Chrome, type: chrome; For Firefox, type: firefox");
            }
        }
    }
}
于 2020-07-17T02:26:35.420 回答