ElementNotVisbleError(无法单击元素)

时间:2017-11-08 00:54:22

标签: html excel vba selenium-webdriver web-scraping

拜,

我正在使用Selenium和Excel VBA编写代码来搜索网站。有问题的网站有一个菜单栏,其中菜单选项只有在悬停时才能看到VBA(类="悬停"当光标在文本上时,类=""当光标不在文本上方)。此外,在加入我的代码时,我无法使用自动化或手动点击链接。

请参阅以下代码:

WebsiteURL = "https://navinet.navimedix.com/signed-out/session-expired?
ReturnUrl=/"
driver.Get WebsiteURL
driver.Window.Maximize
driver.FindElementById("LoginPortletUsername").SendKeys (UserName) 'Reads 
Username
driver.FindElementById("LoginPortletPassword").SendKeys (Password) 'Reads 
password
driver.FindElementById("btnSignInSubmit").Click
Application.Wait (Now + TimeValue("0:00:20"))
driver.FindElementById("mh-workflows-my-health-plans-menu").Click
driver.FindElementById("workflows-menu-plan-aetna").Click
Application.Wait (Now + TimeValue("0:00:10"))
driver.Window.Activate
driver.FindElementById("aetna-eligibility").Click 

代码一直有效,但是以下访问menupath的选项不起作用。

选项1(移动光标和点击)

SetCursorPos 2221, 289
Call SingleClick

使用

Private Sub SingleClick()
SetCursorPos 2286, 69 'x and y position for Health Edge search
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long 'mouse position
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) 'user environment
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10

选项2(移动光标和查找新类)

SetCursorPos 2221, 289
driver.FindElementByClass("hovered").Click

选项3(直接查找对象)

driver.FindElementByXPath("//*[@id='vertical-menu']/li[4]/ul/li/a").Click

选项4(通过菜单路径使用移动到元素并单击)

Set we = driver.FindElementByXPath("//*[@id='vertical-menu']/li[4]/ul/li/a") 
driver.Actions.MoveToElement(driver.FindElementById("aetna-eligibility")).MoveToElement(we).Click.Perform

任何提示或替代方案都会有很大帮助。这让我疯狂!

0 个答案:

没有答案