English 中文(简体)
表格中一个链接的扫描
原标题:Clicking on a link in a table
  • 时间:2012-01-13 14:18:01
  •  标签:
  • webdriver

我有四个栏。 第1栏中的数据是一个小组的名称,我可以点击到一个新网页,以修改小组的数据。

我可以拿到该团体的名称,但我无法点击。 I m试图通过每一行并取得每一组地位(列于第4栏)。 如果搁置的话,我想修改该小组的数据。

我的守则是: 为什么不点击集团的名称?

List<WebElement> elems = driver.findElements(By.xpath("//table[@id= nameOfTable ]/tbody/tr"));
for (WebElement rowElem : elems)
{
    List<WebElement> cells = rowElem.findElements(By.xpath("td"));

    if(cells.get(3).getText().equalsIgnoreCase("Hold"))
    {
        System.out.println(cells.get(0).getText()); //
        cells.get(0).click; // This will not click on the link
    }
}
最佳回答

您需要说<代码>cells.get(0)click();。

I believe you are missing a couple of parentheses...

问题回答

It is because you are clicking the whole cell, not the link inside the cell. Try:

cells.get(0).findElements(By.TagName("a")).Click();

If the link is an <a> tag it will work, but you can use id, classname, etc... if it isn t.





相关问题
How to check if an element is visible with WebDriver

With WebDriver from Selenium 2.0a2 I am having trouble checking if an element is visible. WebDriver.findElement returns a WebElement, which unfortunately doesn t offer an isVisible method. I can go ...

How do I change the default request timeout for Selenium 2?

I am currently using Selenium 2.0a2 in Java to access the Internet using an HtmlUnitDriver instance. The problem I am facing is that, when I attempt to access slow websites, the request times out. How ...

WebRat+Selenium WebDriver: wait for ajax to be completed

We are running Webrat with Selenium2.0 aka WebDriver in our application. WebDriver handles page reloading very well and do not start next steps if the browser is reloading entire page. The problem is ...

How to delete Firefox cookies from webdriver in python?

when I can t delete FF cookies from webdriver. When I use the .delete_all_cookies method, it returns None. And when I try to get_cookies, I get the following error: webdriver_common.exceptions....

How to change firefox proxy from webdriver?

how can I access Firefox proxy settings from Python Webdriver and change them to make Firefox use modified proxy settings without needing to restart it?

热门标签