小编Rob*_*nar的帖子

使用Selenium Webdriver和Python从XPath中提取链接?

我对Seleniun WebDriver和Python很陌生,我的问题可能很基础.

所以,我有以下HTML代码:

<a class="wp-first-item" href="admin.php?page=account">Account</a>
Run Code Online (Sandbox Code Playgroud)

而且我想提取HREF出来的,是XPath的手段,知道它的XPath是".//*[@id='toplevel_page_menu']/ul/li[2]/a".

我怎么做?

driver.find_element_by_xpath(".//*[@id='toplevel_page_menu']/ul/li[2]/a").link
Run Code Online (Sandbox Code Playgroud)

要么

driver.find_element_by_xpath(".//*[@id='toplevel_page_menu']/ul/li[2]/a").href
Run Code Online (Sandbox Code Playgroud)

似乎没有工作,导致:

AttributeError: 'WebElement' object has no attribute 'link'
Run Code Online (Sandbox Code Playgroud)

我期待结果如此"admin.php?page=account".

python python-2.7 selenium-webdriver

7
推荐指数
1
解决办法
7998
查看次数

标签 统计

python ×1

python-2.7 ×1

selenium-webdriver ×1