选择与Selenium Webdriver的链接? [英] Selecting a link with Selenium Webdriver?

查看:59
本文介绍了选择与Selenium Webdriver的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择带有Selenium Webdriver的链接?

How can I select a link with selenium webdriver?

硒可以通过以下方式完成:

Selenium before would be done by:

    selenium.click("link=Users");

但是我该如何使用webdriver?

But how can I do the same with webdriver?

我考虑过

    driver.findElement(By.partialLinkText("Users")).click();

但是这不起作用.没有链接被点击!

but this does not work. No link is clicked!

<html>
<body>
<div id="mainpage" class="mainpage">
<div id="pageid" class="pageid">
<div id="body">

<table>
<tbody>
<tr>
<td>
<table>
<tbody>
<tr>
<td>
<div id="id_menu" class="mymenu">
<ul>
<li class="li_class ">
<a href="/user.xhtml">Users</a>

stacktrace:

stacktrace:

    org.openqa.selenium.NoSuchElementException: Unable to locate element: 
{"method":"partial link text","selector":"Users"} Command duration or timeout: 11.36 
seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions
/no_such_element.html Build info: version: '2.24.1', revision: '17205', time: '2012-06-19 
17:28:14' System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', 
java.version: '1.7.0_02' Driver info: driver.version: RemoteWebDriver Session ID: 
178449d1-4ff3-44f3-b35c-6a158db7c430 error at line: 34

推荐答案

XPath是 point 元素的最精确方法之一.

XPath is one of the most exact ways to point the element.

尝试一下:

driver.findElement(By.XPath("//li[@class='li_class']/a")).Click();

这篇关于选择与Selenium Webdriver的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆