如何单击Dojo-heavy web上的按钮
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何单击Dojo-heavy web上的按钮相关的知识,希望对你有一定的参考价值。
我在使用python + selenium + phantomjs进行自动网络测试时遇到了问题。
网络是Dojo沉重的网络应用程序。为了修改记录,我需要先点击drop_button 修改
,然后点击“修改”但它始终报告找不到元素。
有人可以帮我看一下吗? “modify”元素是display:none
,我试图使用JS启用它,但失败了。
这是修改
元素的来源
<div class="dijit dijitLeft dijitInline dijitDropDownButton" dojoattachevent="onmouseenter:_onMouse,onmouseleave:_onMouse,onmousedown:_onMouse,onclick:_onDropDownClick,onkeydown:_onDropDownKeydown,onblur:_onDropDownBlur,onkeypress:_onKey" widgetid="dijit_form_DropDownButton_6">
<div class="dijitRight">
<button class="dijitStretch dijitButtonNode dijitButtonContents" type="button" dojoattachpoint="focusNode,titleNode" wairole="button" waistate="haspopup-true,labelledby-dijit_form_DropDownButton_6_label" role="button" aria-haspopup="true" aria-labelledby="dijit_form_DropDownButton_6_label" id="dijit_form_DropDownButton_6" tabindex="-1" aria-valuenow="" aria-disabled="false">
<div class="dijitInline " dojoattachpoint="iconNode"></div><span class="dijitButtonText" dojoattachpoint="containerNode,popupStateNode" id="dijit_form_DropDownButton_6_label">修改</span><span class="dijitA11yDownArrow">▼</span>
</button>
</div>
</div>
这是modify
元素的来源:
<table class="dijit dijitMenu dijitReset dijitMenuTable" wairole="menu" dojoattachevent="onkeypress:_onKeyPress" role="menu" id="dijit_Menu_32" widgetid="dijit_Menu_32" style="display: none;">
<tbody class="dijitReset" dojoattachpoint="containerNode">
<tr class="dijitReset dijitMenuItem" dojoattachevent="onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick" id="dijit_MenuItem_76" widgetid="dijit_MenuItem_76" tabindex="-1">
<td class="dijitReset">
<div class="dijitMenuItemIcon " dojoattachpoint="iconNode"></div>
</td>
<td tabindex="-1" class="dijitReset dijitMenuItemLabel" dojoattachpoint="containerNode" wairole="menuitem" role="menuitem" aria-disabled="false">Modify</td>
<td class="dijitReset" dojoattachpoint="arrowCell">
<div class="dijitMenuExpand" dojoattachpoint="expand" style="display:none"><span class="dijitInline dijitArrowNode dijitMenuExpandInner">+</span></div>
</td>
</tr>
<tr class="dijitReset dijitMenuItem" dojoattachevent="onmouseenter:_onHover,onmouseleave:_onUnhover,ondijitclick:_onClick" id="dijit_MenuItem_77" widgetid="dijit_MenuItem_77" tabindex="-1">
<td class="dijitReset">
<div class="dijitMenuItemIcon " dojoattachpoint="iconNode"></div>
</td>
<td tabindex="-1" class="dijitReset dijitMenuItemLabel" dojoattachpoint="containerNode" wairole="menuitem" role="menuitem" aria-disabled="false">Clone</td>
<td class="dijitReset" dojoattachpoint="arrowCell">
<div class="dijitMenuExpand" dojoattachpoint="expand" style="display:none"><span class="dijitInline dijitArrowNode dijitMenuExpandInner">+</span></div>
</td>
</tr>
</tbody>
</table>
这是代码:
menu = driver.find_element_by_css_selector("#dijit_form_DropDownButton_0")
hidden_submenu = driver.find_element_by_css_selector("#dijit_MenuItem_31 > td:nth-child(2)")
actions = webdriver.common.action_chains.ActionChains(driver)
actions.move_to_element(menu)
actions.click(hidden_submenu)
actions.perform()
答案
我看到你的代码非常类似于selenium action chains的例子,为什么不让它变得更简单?你只是转移到修改
菜单而没有点击它,所以当你试图点击子菜单时将找不到
无论如何,如果点击修改
已经执行但你仍然无法点击子菜单,我建议在点击之间添加一个硬编码的等待时间,如:
import time
time.sleep(3)
如果这样做,请执行动态等待时间而不是硬编码
以上是关于如何单击Dojo-heavy web上的按钮的主要内容,如果未能解决你的问题,请参考以下文章
用户单击 ASP.NET Web 表单上的按钮与计时器运行调用相同按钮单击事件的方法之间的区别?