使用python + selenium + phantomjs进行自动网络测试时遇到问题。
Web是Dojo繁重的Web应用程序。为了修改记录,我需要先单击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()
答案 0 :(得分:0)
我看到您的代码与selenium action chains的示例非常相似,为什么不简化它呢?您只是移至修改
菜单,而不执行单击,所以当您尝试单击子菜单时,将不会找到
无论如何,如果执行了修改
单击,但仍然无法单击子菜单,我建议在两次单击之间添加一个硬编码的等待时间,例如:
import time
time.sleep(3)
如果可行,请执行动态等待时间,而不要执行硬编码