无头镀铬不适用于头部工程

时间:2018-02-13 22:20:08

标签: vb.net selenium selenium-chromedriver

所以我有一个功能版本,头上有selenium chrome驱动程序。但是当我尝试没有头(无头)时,它只是因为某种原因而去捕获。

无头代码:

        Dim driveroptions As ChromeOptions = New ChromeOptions()
        If TextBox1.Text = "" Then
            driveroptions.AddArgument("--user-data-dir=C:\\Users\\" + GetUserName() + "\\AppData\\Local\\Google\\Chrome\\User Data\\")
        Else
            driveroptions.AddArgument("--user-data-dir=" + TextBox2.Text)
        End If
        driveroptions.AddArgument("--headless")
        Dim service As ChromeDriverService = ChromeDriverService.CreateDefaultService
        service.HideCommandPromptWindow = True
        Dim driver2 As IWebDriver = New ChromeDriver(service, driveroptions)

        Dim UserName_TextBox As IWebElement
        Dim Password_TextBox As IWebElement
        Dim No_Save_Password As IWebElement

        If CheckBox1.Checked = False Then
            Try
                driver2.Navigate().GoToUrl("url")
                Thread.Sleep("5000")
                driver2.SwitchTo.Frame(0)
                UserName_TextBox = driver2.FindElement(By.Name("user"))
                UserName_TextBox.Click()
                UserName_TextBox.SendKeys(username)
                driver2.SwitchTo().DefaultContent()
                driver2.SwitchTo().Frame(0)
                Password_TextBox = driver2.FindElement(By.Name("password"))
                Password_TextBox.Click()
                Password_TextBox.SendKeys(password)
                Password_TextBox.Submit()
                driver2.SwitchTo().DefaultContent()
                driver2.SwitchTo().Frame(0)
                Thread.Sleep(3500)
                No_Save_Password = driver2.FindElement(By.CssSelector("#modal > div > div > div > div.pill-wrap.double > a:nth-child(1)"))
                No_Save_Password.Click()
                Thread.Sleep(1000)
                driver2.Quit()

            Catch ex As Exception
               ''do error stuff here
            End Try

0 个答案:

没有答案