excel vba - Selenium 查找元素
excel vba - Selenium Find Element
我正在使用 Selenium 进行一些网页抓取。
当名称或 ID 不是一个选项时,我总是很难找到元素。
页面是
https://www.portfolio123.com/holdings.jsp?portid=1637063
我正在寻找登录按钮。
该元素看起来像:
我试过了
FindElementByClass("btn-primary btn-sm", 10000)
FindElementsByLinkText("Log In", 10000)
FindElementByXPath("//div[@class='btn btn-primary btn-sm']//[@href='javascript:void(goToLoginPage())")
但没有任何成功(我怀疑我需要使用 XPath,但我似乎无法正确使用
有什么帮助吗? (如果你能解释如何解决这个问题,那么我以后就没有问题了,我将不胜感激)
我测试了。在代码下方尝试此代码。它对我有用..
子登录码()
Dim bot 作为新的 WebDriver
bot.start "chrome", "https://www.portfolio123.com/holdings.jsp?portid=1637063"
bot.Get“/”
调用 WaitForSec(5)
bot.FindElementByXPath("//*[@id=""wrapper""]/div/div/div/a[1]").点击
结束子
Sub WaitForSec(秒为整数)
将lngTime变暗
lngTime = Timer
While Timer < lngTime + Sec
DoEvents
Wend
结束子
要找到元素 登录,您可以使用以下任一方法 :
使用 FindElementByLinkText:
FindElementByLinkText("Log In")
使用 FindElementByCss:
FindElementByCss("a[href*='goToLoginPage']")
使用 FindElementByXPath:
FindElementByXPath("//a[contains(@href, 'goToLoginPage')]")
我正在使用 Selenium 进行一些网页抓取。
当名称或 ID 不是一个选项时,我总是很难找到元素。
页面是 https://www.portfolio123.com/holdings.jsp?portid=1637063
我正在寻找登录按钮。
该元素看起来像:
我试过了
FindElementByClass("btn-primary btn-sm", 10000)
FindElementsByLinkText("Log In", 10000)
FindElementByXPath("//div[@class='btn btn-primary btn-sm']//[@href='javascript:void(goToLoginPage())")
但没有任何成功(我怀疑我需要使用 XPath,但我似乎无法正确使用
有什么帮助吗? (如果你能解释如何解决这个问题,那么我以后就没有问题了,我将不胜感激)
我测试了。在代码下方尝试此代码。它对我有用..
子登录码()
Dim bot 作为新的 WebDriver
bot.start "chrome", "https://www.portfolio123.com/holdings.jsp?portid=1637063"
bot.Get“/”
调用 WaitForSec(5)
bot.FindElementByXPath("//*[@id=""wrapper""]/div/div/div/a[1]").点击
结束子
Sub WaitForSec(秒为整数)
将lngTime变暗
lngTime = Timer
While Timer < lngTime + Sec
DoEvents
Wend
结束子
要找到元素 登录,您可以使用以下任一方法
使用 FindElementByLinkText:
FindElementByLinkText("Log In")
使用 FindElementByCss:
FindElementByCss("a[href*='goToLoginPage']")
使用 FindElementByXPath:
FindElementByXPath("//a[contains(@href, 'goToLoginPage')]")