F
F
froja2021-06-17 15:42:51
Python
froja, 2021-06-17 15:42:51

How to pull data from popup element in Python Selenium?

I'm parsing Ozone using Python Selenium and Firefox webdriver, I need to extract PSRN and sellers name from product card, but I can't extract them because I get below error:
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: ._29Sp

On the screen there is a button that you need to click on in order for the element to appear, which contains the OGRN and the seller.
60cb42c261822107915407.jpeg

Card example: https: //www.ozon.ru/context/detail/id/208499908/ ?a...

for link in links:
                driver.get(link)
                time.sleep(3)

                ogrn_button = driver.find_element_by_class_name('d4w7').find_element_by_class_name('b1c6').find_element_by_class_name('_3zcl')
                if not ogrn_button:
                    pass
                else:
                    action = ActionChains(driver)
                    driver.execute_script('window.scrollTo(1280, 675)')
                    time.sleep(2)
                    action.click().perform()
                    time.sleep(1)
                    ogrn_field = driver.find_element_by_class_name('_29Sp')
                    ogrn = ogrn_field.find_elements_by_tag_name('p')[1].text
                    seller = ogrn_field.find_element_by_tag_name('p').text

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-06-17
@froja

1. The button was not pressed, the data appears only after that
ogrn_button.click()
2. There are several elements on the page with the class _29Sp, so I advise you to choose a better selector

V
Vasily, 2021-06-18
@snaiper04ek

I don’t know how to do it right, but if there are problems with understanding how to aim, then you can do it like me -
I learned to aim elements through the web version of selenium (browser add-on), it’s convenient to just aim at the element with the mouse and get the finished code, then minimal editing is required if the mouse missed or clarification is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question