我想启动一个浏览器,然后单击一个无法通过选项卡访问的元素,这样我就不能使用SendKeys。如果它在internet explorer上,我会尝试使用ie.document.getElementByName函数,但这不是一个选择,因为我是通过shell函数启动Google Chrome的(参见下面的代码了解Chrome启动方法)。当没有对象可供.document.getElementByName调用时,有没有办法仍然访问html元素?
Dim chromePath As String
chromePath = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
Shell (chromePath & " -url https://clients.mindbodyonline.com/Report/Sales/Sales/Generate?reportID=undefined")
发布于 2018-07-04 05:44:46
如果您通过selenium进行启动,则很容易。要附加到现有的浏览器实例上要困难得多(如果不是不可能的话),例如,从命令行启动的浏览器实例与当前WebDriver实例所使用的不同。
我想说的是,因为你的命令行操作是通过Shell
完成的,而且只是启动Chrome,所以你可以简单地安装selenium basic,添加对selenium type library
的引用,然后使用selenium打开Chrome,如下所示:
Option Explicit
Public Sub OpenChromeAndSelect()
'References to Selenium type library
Dim d As WebDriver, el As WebElement
Set d = New ChromeDriver
Const URL = "https://clients.mindbodyonline.com/Report/Sales/Sales/Generate?reportID=undefined"
With d
.Start "Chrome"
.get URL
Set el = .FindElementById("myID")
'Do other stuff
'.Quit
End With
End Sub
https://stackoverflow.com/questions/51162611
复制相似问题