问题描述
我在eclipse中使用Selenium IDE和Selenium web驱动程序测试..
我的测试是针对ZK应用程序..
I am using Selenium IDE and Selenium web driver testng in eclipse ..my testing is against ZK application ..
测试用例正常工作Selenium IDE ..
the test case works fine on 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://*****/>
<title>work it2</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">work it2</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/xxx</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//li[2]/div/div/div/span</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>3000</td>
<td>3000</td>
</tr>
<tr>
<td>doubleClick</td>
<td>//div[2]/div[2]</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>3000</td>
<td>3000</td>
</tr>
</tbody></table>
</body>
</html>
但是当我使用selenium web driver(testng)在eclipse中运行它时出现错误..
but when I run it in eclipse with selenium web driver (testng) I got an error ..
selenium.open("xxx");
selenium.click("//li[2]/div/div/div/span");
Thread.sleep(3000);
selenium.doubleClick("//div[2]/div[2]");
Thread.sleep(3000);
我还将代码更改为
driver.get("xxx");
driver.findElement(By.xpath("//li[2]/div/div/div/span")).click();
Thread.sleep(3000);
WebElement ee = driver.findElement(By.xpath("//div[2]/div[2]"));
Actions action = new Actions(driver);
action.doubleClick(ee).perform();
Thread.sleep(3000);
也得到同样的错误......
also getting the same error ...
//div[2]/div[2]
推荐答案
Naif,
其实,你的以上问题与实际问题不同,因此您应该将其作为单独的问题提出。不过,我正在回答你之前提出的问题。
Actually, your above question is different than the actual question hence you should have asked it as a separate question. Still, I'm answering to your previous question.
错误是因为您尝试点击的元素不可见。在单击元素之前,它应该是可见的。您可以通过以下方式完成此操作 -
The error is because the element you're trying to click on isn't visible. Before you click on element, it should be visible. You can do this by following -
WebElement element = driver.findElement(By.xpath("//div[2]/div[2]"));
WebDriverWait wait = new WebDriverWait(driver, 20); //here, wait time is 20 seconds
wait.until(ExpectedConditions.visibilityOf(element)); //this will wait for elememt to be visible for 20 seconds
element.click(); //now it clicks on element
如果上面不起作用,你可以点击元素执行javascript(但这不是一个好习惯)
If above doesn't work, you can click on element by executing javascript(but this isn't a good practice)
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
这篇关于Selenium web驱动程序:无法滚动到视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!