![Creative The name of the picture]()

Clash Royale CLAN TAG#URR8PPP
How to construct an XPath to extract the url www.fastreact.co.uk from the parent ul tag?
Hi I want to navigate to this exact vendor url using selenium <li>www.fastreact.co.uk</li>
. But I'm stuck at this part.
<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]')
How do I navigate to that exact UL? From what I can see in the source code there are four occurrences where a UL contains the class="check-list ... "
.
Also once I manage to navigate to that node how do I output that selenium web element into human text?
class="check-list ... "
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>
<ul class="check-list ...
//ul[@class="check-list"][3]/li[2]/text()
2 Answers
2
Here is a working example of what you are wanting:
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)
The print statements will display the text values of the elements in your console.
As per your question to extract the Vendor URL you need to induce WebDriverWait for the desired element to be visible and you can use the following solution:
Code Block:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument('disable-infobars')
driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:UtilityBrowserDriverschromedriver.exe')
driver.get("https://www.capterra.com/p/14890/Fastreact/")
print(WebDriverWait(driver, 20).until(expected_conditions.visibility_of_element_located((By.XPATH, "//h2[@class='epsilon' and contains(.,'Vendor Details')]//following::ul[1]//following-sibling::li[2]"))).get_attribute("innerHTML"))
Console Output:
www.fastreact.co.uk
'document.readyState' equal to "complete"
readyState == "complete"
"interactive"
readyState == "complete"
readyState == "complete"
"interactive"
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Try this: //ul[@class="check-list"]/li[2]/text()
– Gabrielius
yesterday