简体   繁体   English

错误元素当前不可见,因此可能无法与Selenuim交互

[英]error Element is not currently visible and so may not be interacted with Selenuim

I am using Selenium to record my actions on a webpage, however, when I play the test case, there is an click action throwing error: Element is not currently visible and so may not be interacted with. 我正在使用Selenium在网页上记录我的操作,但是,当我播放测试用例时,会发生单击操作抛出错误:当前不可见元素,因此可能无法与之交互。 However, I am sure that button is visible, and here is html for it: 但是,我确定该按钮是可见的,并且此处是html:

<button class="btn btn-success btnSubmit" style="font-size: 1.9em; width: 100%; height: 2em; margin-top: 20px;" type="submit"> Get Your Report </button>

Also, here is my test script for Selenium IDE: 另外,这是我的Selenium IDE测试脚本:

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://hra.case.edu/" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
    <td>open</td>
    <td>/</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>link=Get Started</td>
    <td></td>
</tr>
<tr>
    <td>keyPress</td>
    <td>name=searchFirstName</td>
    <td>Tiancheng</td>
</tr>
<tr>
    <td>waitForElementPresent</td>
    <td>//div[@id='content']//tbody[@id='select_user']/tr[1]//a</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>//div[@id='content']//tbody[@id='select_user']/tr[1]//a</td>
    <td></td>
</tr>
<tr>
    <td>type</td>
    <td>id=answer_heightFoot</td>
    <td>5</td>
</tr>
<tr>
    <td>type</td>
    <td>id=answer_heightInch</td>
    <td>11</td>
</tr>
<tr>
    <td>type</td>
    <td>id=answer_weight</td>
    <td>222</td>
</tr>
<tr>
    <td>select</td>
    <td>id=answer_bodySize</td>
    <td>label=Medium</td>
</tr>
<tr>
    <td>click</td>
    <td>id=answer_diabetes_no</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>link=Other</td>
    <td></td>
</tr>
<tr>
    <td>clickAndWait</td>
    <td>id=next</td>
    <td></td>
</tr>
<tr>
    <td>waitForElementPresent</td>
    <td>//button[@type='submit']</td>
    <td></td>
</tr>
<tr>
    <td>verifyElementPresent</td>
    <td>//button[@type='submit']</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>//button[@type='submit']</td>
    <td></td>
</tr>
</tbody></table>
</body>
</html>

Anyone has an idea of why? 有人知道为什么吗? Thanks in advance! 提前致谢!

Some webelement may be present at DOM but be invisible at the same time. DOM中可能存在某些Web元素,但同时它们是不可见的。 So, after you perform some action use waitForVisible method to wait for element to become visible and interactible 因此,在执行某些操作后,请使用waitForVisible方法等待元素变为可见且可交互

UPDATE : @Kees de Kooter, here's the working example 更新 :@Kees de Kooter,这是工作示例

<tr>
    <td>open</td>
    <td>http://stackoverflow.com/</td>
    <td></td>
</tr>
<tr>
    <td>click</td>
    <td>css=.js-help-button</td>
    <td></td>
</tr>
<tr>
    <td>waitForElementPresent</td>
    <td>css=.js-help-button</td>
    <td></td>
</tr>
<tr>
    <td>waitForVisible</td>
    <td>css=.js-help-dialog</td>
    <td></td>
</tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM