如何将这些C#代码转换为VB .NET?我只是想不通。
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
var driver = new ChromeDriver(driverService, new ChromeOptions());
或
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
var option = new ChromeOptions();
option.AddArguments("--headless", "--no-sandbox", "--disable-web-security", "--disable-gpu", "--incognito", "--proxy-bypass-list=*", "--proxy-server='direct://'", "--log-level=3", "--hide-scrollbars");
driver = new ChromeDriver(chromeDriverService, options);
我只想在运行时隐藏窗口控制台。
答案 0 :(得分:1)
以下是Telerik的Code Converter产生的转换:
Dim driverService = ChromeDriverService.CreateDefaultService()
driverService.HideCommandPromptWindow = True
Dim driver = New ChromeDriver(driverService, New ChromeOptions())
...和
Dim chromeDriverService = ChromeDriverService.CreateDefaultService()
chromeDriverService.HideCommandPromptWindow = True
Dim [option] = New ChromeOptions()
[option].AddArguments("--headless", "--no-sandbox", "--disable-web-security", "--disable-gpu", "--incognito", "--proxy-bypass-list=*", "--proxy-server='direct://'", "--log-level=3", "--hide-scrollbars")
driver = New ChromeDriver(chromeDriverService, options)
-编辑-
这是完整样本中的更正代码:
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Keys
Imports OpenQA.Selenium.Chrome
Imports System.Threading.Thread
Imports System.Data.Odbc
Imports System.Text.RegularExpressions
Public Class Form1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
driverService = ChromeDriverService.CreateDefaultService()
driverService.HideCommandPromptWindow = True
driver = New ChromeDriver(driverService, New ChromeOptions())
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
driver.Navigate().GoToUrl("http://www.google.com")
End Sub
Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
btnStop.Text = "Stopping service..."
btnStop.Enabled = False
driver.Quit()
driver.Dispose()
btnStop.Text = "Done."
End Sub
Private driverService As ChromeDriverService
Private driver As IWebDriver
End Class
请注意,driver
和driverService
在班上是Fields
。有关类字段的更多信息,请参见官方文档here:
字段和属性
字段和属性表示存储在对象中的信息。您可以使用赋值语句检索和设置它们的值,就像在过程中检索和设置局部变量一样。下面的示例检索Width属性并设置Label对象的ForeColor属性。
Dim warningWidth As Integer = warningLabel.Width warningLabel.ForeColor = System.Drawing.Color.Red
如果要针对Object
的{{1}}执行代码,例如将Property
设置为driverService.HideCommandPromptWindow
,则该操作必须在{{1} },True
或Method
。在这种情况下,该特定代码行在表单的构造函数Function
中运行。
只要有机会,Microsoft文档的这些部分对您来说都是非常好的读物。
答案 1 :(得分:0)
感谢InteXX的回复。
这是我的代码问题:
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Keys
Imports OpenQA.Selenium.Chrome
Imports System.Threading.Thread
Imports System.Data.Odbc
Imports System.Text.RegularExpressions
Public Class Form1
Dim driverService = ChromeDriverService.CreateDefaultService()
driverService.HideCommandPromptWindow = True
Dim driver As IWebDriver = New ChromeDriver(driverService, New ChromeOptions())
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
driver.Navigate().GoToUrl("http://www.google.com")
End Sub
Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
btnStop.Text = "Stopping service..."
btnStop.Enabled = False
driver.Quit()
driver.Dispose()
btnStop.Text = "Done."
End Sub
End Class
如果将其放在方法或子代码中,我不知道如何使用驱动程序变量。