0

Here is the code of the web

enter image description here

The xpath of search-results-list container grid is

 //[@id="product_type_products_list"]/div/div[2]/div

and the xpath of result is

 //*[@id="product_type_products_list"]/div/div[2]/div/div[1]

I have try using :

elems = driver.find_elements_by_xpath('//*[@id="product_type_products_list"]/div/div[2]/div')
url = driver.find_element_by_link_text(elems[0].text).get_attribute("href")
print(url)

this give the link to the beginning of the web.

Thank you for your consideration.

2 Answers 2

1

The code you've provided doesn't look like a valid HTML to me, however you can try the following XPath expression:

//div[@class='result']/descendant::a

enter image description here

More information:

Sign up to request clarification or add additional context in comments.

1 Comment

I don't know whether i can post like this,i edited the question anywhere thank for your help.
1

Try Narrowing it down to the <'A> Tag by appending the xpath like so:

elems = driver.find_elements_by_xpath('.//*[@id="product_type_products_list"]/div/div[2]/div/div[1]/a')

Then just retrieve the href attribute like you did earlier but using the same element:

url = elems[0].get_attribute("href")

2 Comments

in your answer, elems is a list of elements, which does not have a get_attribute method.
Thanks for pointing it out Corey. I added the index in there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.