使用SeleniumBasic for vba选择隐藏菜单项时出现问题
我在使用vba选择工作网页上的隐藏菜单项时遇到问题。我曾尝试使用使用SeleniumBasic for vba选择隐藏菜单项时出现问题,vba,selenium-webdriver,selenium-chromedriver,Vba,Selenium Webdriver,Selenium Chromedriver,我在使用vba选择工作网页上的隐藏菜单项时遇到问题。我曾尝试使用WebDriver.Mouse.Mouse to将鼠标悬停在每个菜单选项上,以便选择嵌套在其下方的对象,但在第一次悬停后,找不到该对象 在下图中,我打算这样导航: Pricing Admin System Admin Multi-PAG Upload 为此,我必须将鼠标悬停在定价管理上,然后将鼠标悬停在系统管理上,这样菜单就会显示为单击多页上传。我已经成功地让驱动程序将鼠标悬停在定价管理上,这将显示第一个
WebDriver.Mouse.Mouse to
将鼠标悬停在每个菜单选项上,以便选择嵌套在其下方的对象,但在第一次悬停后,找不到该对象
在下图中,我打算这样导航:
Pricing Admin
System Admin
Multi-PAG Upload
为此,我必须将鼠标悬停在定价管理上,然后将鼠标悬停在系统管理上,这样菜单就会显示为单击多页上传。我已经成功地让驱动程序将鼠标悬停在定价管理上,这将显示第一个菜单列表,其中有三个项目以系统管理结尾。然而,为系统管理员尝试FindElement()
,以便我可以在上面悬停,这被证明是非常困难的
根据我尝试的方法,我倾向于获得所需的对象
错误或XPath选择器无效
。我在设置系统管理员=
时开始出现问题
欢迎任何建议
Public Sub SeleniumTest()
Dim driver As New WebDriver
'open chrome to site
driver.start "chrome"
driver.Get "http://www.website.net"
'login
driver.FindElementByName("j_username").SendKeys ("user")
driver.FindElementByName("j_password").SendKeys ("pass")
driver.FindElementById("submit_button").Click
'hover over Pricing Admin
Dim pricingAdmin As WebElement
Set pricingAdmin = driver.FindElementById("prcngAdmMnuFrm:prcngAdmMnu")
driver.Mouse.MoveTo pricingAdmin
Dim systemAdmin As WebElement
'neither selection method below works properly
' Set systemAdmin = driver.FindElementByXPath("//*[contains(text(),'System Admin')]")
' Set systemAdmin = driver.FindElementByXPath("//div[@id='prcngAdmMnuFrm:prcngAdmMnu']/div/div/ul/li/ul/li[3]/ul/li[4]/a/span/span")
driver.Mouse.MoveTo systemAdmin
Dim multiPagUpload As WebElement
' Set multiPagUpload = driver.FindElement("??")
multiPagUpload.Click
'closes browser window
driver.Quit
End Sub
以下是该网站的(节略)HTML。为了简单起见,我删掉了一些列表,但若确实有必要(使用javascript等),请告诉我,我可以插入更多
<div id="prcngAdmMnuFrm:prcngAdmMnu" style="">
<div class="ui-widget ui-widget-content wijmo-wijmenu ui-corner-all ui-helper-clearfix wijmo-wijmenu-horizontal" aria-activedescendant="ui-active-menuitem" role="menubar">
<div class="scrollcontainer checkablesupport">
<ul style="display: block;" class="wijmo-wijmenu-list ui-helper-reset" tabindex="0">
<li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all wijmo-wijmenu-parent" aria-haspopup="true" style="">
<a href="#" class="wijmo-wijmenu-link ui-corner-all" id="">
<span class="wijmo-wijmenu-text">
<span class="wijmo-wijmenu-text">Pricing Admin</span>
</span>
<span class="ui-icon ui-icon-triangle-1-s"></span>
</a>
<ul class="wijmo-wijmenu-list ui-widget-content ui-corner-all ui-helper-clearfix wijmo-wijmenu-child" style="display: none; left: 0px; top: 38px; position: absolute; list-style-type: none;" aria-hidden="true">
<li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all wijmo-wijmenu-parent" aria-haspopup="true" style="">
<a href="#" class="wijmo-wijmenu-link ui-corner-all ui-state-focus">
<span class="wijmo-wijmenu-text">
<span class="wijmo-wijmenu-text">System Admin</span>
</span>
<span class="ui-icon ui-icon-triangle-1-e"></span>
</a>
<ul class="wijmo-wijmenu-list ui-widget-content ui-corner-all ui-helper-clearfix wijmo-wijmenu-child" style="display: none; left: 215px; top: -1px; position: absolute; list-style-type: none;" aria-hidden="true">
<li role="menuitem" class="ui-widget wijmo-wijmenu-item ui-state-default ui-corner-all">
<a onclick="showProcessingMessage('Loading');;var self = this; setTimeout(function() { var f = function(opt){ice.ace.ab(ice.ace.extendAjaxArgs({"source":"prcngAdmMnuFrm:menu_pad_sa_multi","execute":'@all',"render":'@all',"event":"activate"}, opt));}; f({node:self});}, 10);" style="cursor:pointer;" class="wijmo-wijmenu-link ui-corner-all">
<span class="wijmo-wijmenu-text">
<span class="wijmo-wijmenu-text">Multi-PAG Upload</span>
</span>
</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<script type="text/javascript">
var widget_prcngAdmMnuFrm_prcngAdmMnu = ice.ace.create("Menubar", ["prcngAdmMnuFrm:prcngAdmMnu", {
"autoSubmenuDisplay": true,
"direction": "auto",
"animation": {
"animated": "fade",
"duration": 400
}
}]);
</script>
</div>
-
-
-
多页上传
var widget_prcngAdmMnuFrm_prcngAdmMnu=ice.ace.create(“菜单栏”、[“prcngAdmMnuFrm:prcngAdmMnu”{
“autoSubmenuDisplay”:true,
“方向”:“自动”,
“动画”:{
“动画”:“淡入淡出”,
“持续时间”:400
}
}]);
如果我遗漏了任何您需要解决的问题,请告诉我 代码中使用的xpath不正确。我的建议是找到锚元素并将鼠标移到上面 #系统管理菜单
'Hover over Pricing Admin
Dim systemAdmin As WebElement
Set systemAdmin = driver.FindElementByXPath("//a[.//span[contains(.,'System Admin')]]")
driver.Mouse.MoveTo pricingAdmin
如果鼠标悬停不起作用,我们仍然可以尝试通过单击锚元素然后发送键(键。箭头\右键)来处理菜单
#多页上传
Dim multiPagUpload As WebElement
Set multiPagUpload = driver.FindElementByXPath("//a[.//span[contains(.,'Multi-PAG Upload')]]")
multiPagUpload.Click
不幸的是,我仍然收到运行时错误“438”:对象不支持行
Set systemAdmin=
@Marcucciboy2上的此属性或方法。让我们尝试直接使用元素而不是分配给变量。driver.Mouse.MoveTo driver.findelementbypath(“//a[.//span[contains(,'System Admin')]]”)更新了代码以删除重复的“driver.driver”。现在试一试哦,天哪,我不敢相信我没有充分证明它,以至于没有注意到额外的驱动程序。
\u>上面的xpath将单击元素的锚定部分,而不是跨度。但它基于子跨度元素上的文本来标识锚定。