XPath如何确定四个UL中的一个?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (153)

我想使用Selenium导航到这个确切的供应商url。<li>www.fastreact.co.uk</li>

vendor_url = browser.find_element_by_xpath('//ul[@class="check-list"]')
#vendor_url = browser.find_element_by_xpath('//ul[@class="check-list"][3]')

我如何导航到精确的UL?从我在源代码中可以看到的情况来看,有四个UL包含class="check-list ... "

同样,一旦我设法导航到那个节点如何将Selenium Web元素输出到human text中?

https://www.capterra.com/p/14890/Fastreact/

<h2 class="epsilon"><i class="ss-buildings  icon-lead  zeta"></i>VendorDetails</h2>

<ul class="check-list" >
    <li>Fast React Systems</li>
    <li>www.fastreact.co.uk</li>
    <li>Founded 1999</li>
    <li>United Kingdom</li>
</ul>
提问于
用户回答回答于

下面是你所需要的工作示例:

NOTE: This was tested using Chrome build 67 with chromedriver 2.40

driver.get('https://www.capterra.com/p/14890/Fastreact/')

# this will go directly to the check-list item you are wanting
vendor_details = driver.find_element_by_xpath('.//ul[@class="check-list"][2]')
print(vendor_details.text)

# this will go directly to the link you are wanting
vendor_link= driver.find_element_by_xpath('.//ul[@class="check-list"][2]/li[2]')
print(vendor_link.text)

print语句将显示控制台中元素的文本值。

扫码关注云+社区

领取腾讯云代金券