元素列表

时间:2010-07-10 15:12:34

标签: xpath selenium count element

我在页面上有一些链接,如:

123test.com/456
abc_test.com/sdfsd
abc_test.org

我必须得到href属性的所有元素都包含 test 字。

我知道如何按给定的号码点击此链接:

selenium.click("//body/descendant::a[contains(@href,'test')][2]")

此代码将点击第二个链接,该地址中包含“test”。但是如何获得那些链接?

1 个答案:

答案 0 :(得分:1)

有功能:

get_xpath_count(self,xpath)
    """
    Returns the number of nodes that match the specified xpath, eg. "//table" would give
    the number of tables.

    'xpath' is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
    """