我在eclipse中使用Selenium IDE和Selenium web驱动程序testng .. 我的测试是针对ZK应用程序..
测试用例在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>
但是当我在eclipse中使用selenium web driver(testng)运行它时出现错误..
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);
也得到同样的错误......
//div[2]/div[2]
com.thoughtworks.selenium.SeleniumException:元素内的偏移量 无法滚动到视图中:(87,118):[对象XrayWrapper [对象 HTMLDivElement]]命令持续时间或超时:63毫秒Build info:version:'2.39.0',修订版:'ff23eac',时间:'2013-12-16 16:11:15'系统信息:主机:'EnD',ip:'192.168.17.76',os.name: 'Windows 7',os.arch:'amd64',os.version:'6.1',java.version: '1.7.0_51'专家ID:3b79783c-2558-4c87-bd51-a72821696040驱动程序 info:org.openqa.selenium.firefox.FirefoxDriver功能 [{platform = XP,acceptSslCerts = true,javascriptEnabled = true, cssSelectorsEnabled = true,databaseEnabled = true,browserName = firefox, handlesAlerts = true,browserConnectionEnabled = true, webStorageEnabled = true,nativeEvents = false,rotate = false, locationContextEnabled = true,applicationCacheEnabled = true, takesScreenshot = true,version = 27.0.1}]
答案 0 :(得分:6)
纳伊夫,
实际上,您的上述问题与实际问题不同,因此您应该将其作为单独的问题提出。不过,我还是回答你以前的问题。
错误是因为您尝试点击的元素不可见。在单击元素之前,它应该是可见的。您可以通过以下方式执行此操作 -
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点击元素(但这不是一个好习惯)
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);
答案 1 :(得分:2)
尝试执行脚本并单击元素
driver.executeScript("arguments[0].click();", element)
答案 2 :(得分:1)
我不确定,但试着看看以下是否适合你。首先,您必须在与之交互之前使该元素可见 -
WebElement element = driver.findElement(By.xpath("//div[2]/div[2]"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
上面的代码将向下滚动,直到元素可见,然后您可以点击它。
答案 3 :(得分:0)
我在稍微不同的上下文中遇到了这个错误,我试图用selenium RemoteWebDriver点击锚标记(我试图替换WebDriver)。该修复程序为驱动程序确定了正确的功能集,例如:
capability = DesiredCapabilities.chrome();
capability.setPlatform(Platform.WIN10);
capability.setCapability("version", "66");
答案 4 :(得分:0)
我只是调整了浏览器的尺寸,效果就这样
driver = webdriver.Firefox()
driver.get(SOME_URL)
driver.set_window_position(0, 0)
driver.set_window_size(1024, 768)