2

I scrapping the marketplace from this URL https://www.tokopedia.com/sunxin

I want to get the data from the button called Info Toko, if user click this will shown a pop up content: enter image description here enter image description here

The original source code for this button is:

<button class="css-rhf1fq-unf-btn e1ggruw00"><span>Info Toko</span></button>

I've tried to get the element by xpath, classname, link text, but still not working.

driver.find_element_by_link_text('Info Toko')

Always get error message like this enter image description here

Any ideas how to get this element?

1

2 Answers 2

2

Try by using xpath selector

In which you want to change your selector code as shown below

driver.find_element_by_xpath('//div[@class="css-ais6tt"]//button[3]')

This will work

0

When ever you use a method read its documentation :

https://selenium-python.readthedocs.io/locating-elements.html

continue_link = driver.find_element_by_link_text('Continue')
continue_link = driver.find_element_by_partial_link_text('Conti')

This two element locators identifies the element only using link text.

In selenium a link is "an anchor tag" , an anchor tag is used wrap a href link

in your case its a button tag and not a anchor 'a' tag, so link text method won't work

use xpath , css or class

xpath:

driver.find_element_by_xpath('//button[text()="Info Toko"]')

css:

css to find using class

driver.find_element_by_css_selector('button.css-rhf1fq-unf-btn.e1ggruw00')

class:

driver.find_element_by_class_name('css-rhf1fq-unf-btn e1ggruw00')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.