Skip to content Skip to sidebar Skip to footer

How To Scrape Data From Webpage Which Uses React.js With Selenium In Python?

I am facing some difficulties scraping a website which uses react.js and not sure why this is happening. This is the html of the website: What I wish to do is click on the button

Solution 1:

Seems you were close. While using find_element_by_class_name() you can't pass multiple classes and you are allowed to pass only one classname, i.e. only only one among either of the following:

  • play-pause-button
  • btn
  • btn-naked

On passing multiple classes through find_element_by_class_name() you will face Message: invalid selector: Compound class names not permitted


Solution

As an alternative, as the element is an Angular element, to click() on the element you have to induce WebDriverWait for the element_to_be_clickable() and you you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.play-pause-button.btn.btn-naked")))click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='play-pause-button btn btn-naked']")))click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC

Post a Comment for "How To Scrape Data From Webpage Which Uses React.js With Selenium In Python?"