0

在 java 中使用 selenium,无法单击按钮。如何使用 xpath 定位元素并单击它?

这是我正在使用的源页面的一部分:

<div id="top-navigation">
<ul class="menu">
<li class="item first active">
<a href="/index.php/sprachen-lernen/englisch">Home</a></li>
<li class="item ">
<a href="/index.php/openArea/school">Online Language School
                </a></li>
<li class="item ">
<a href="/index.php/openArea/partner">Enterprise Solutions
                </a></li>
<li class="item ">
<a href="/index.php/openArea/customer">References
                </a></li>
<li class="item last ">
<a href="/index.php/openArea/contact">Contact</a></li>
</ul>
    <div id="login-button">
                    <a href="/login/login"><img src="/images/openArea/login.png" alt="Login" /></a>
            </div>
</div>

这是我正在使用的声明

driver.findElement(By.id("login-button")).click();

但它没有点击按钮。这是我第一次使用 selenium,所以有人可以指导我说我的陈述有问题,或者如果我想使用 xpath,那么确切的陈述应该是什么

4

1 回答 1

0

我已经使用 firebug 来定位元素的 xpath,现在它可以工作了:)

于 2013-05-15T09:22:14.837 回答