Search code examples
pythonseleniumxpathcss-selectorsclassname

Differences in performance of Selenium on PC and RPI


I have some code that I developed on my PC that checks for the number of likes on a particular blog post. It works perfectly on my PC which is using the latest version of CHrome and ChromeDriver for Python.

However when I transfer this code to my RPI using chromium. It still runs but does not find any of the elements that the version on the PC does.

It is the exact same web page and if I inspect manually the element is there, but the code on the RPI doesn't find it.

Is this related to the amount of memory an RPI has versus my PC or some other hardware related issue?

I don't think it should matter but the element I am trying to find is:

driver.find_elements_by_class_name('like-button.ignore-click.is-animated.has-label')

On WordPress.com sites.

this is similar to this question:

Selenium Error: element not visible (different behaviour on two computers)

However, I have different code that runs fine on both rpi and pc that finds the elements even when they are not visible in the window


Solution

  • In your code block you are trying to pass multiple classes through find_elements_by_class_name(classname)

    As per the documentation of selenium.webdriver.common.by implementation:

    class selenium.webdriver.common.by.By
        Set of supported locator strategies.
    
        CLASS_NAME = 'class name'
    

    So,

    • Using find_element_by_class_name() you won't be able to pass multiple class names.

    You can find a detailed discussion in Invalid selector: Compound class names not permitted using find_element_by_class_name with Webdriver and Python

    Practically, while using like-button.ignore-click.is-animated.has-label as a locator, you are using a .


    Solution

    As a solution you can use either of the following Locator Strategies:

    • Using CSS_SELECTOR:

      driver.find_element_by_css_selector(".like-button.ignore-click.is-animated.has-label")
                        Note the added ^^^ . ^^^ character in the begining
      
    • Using XPATH:

      driver.find_element_by_xpath("//*[@class='like-button ignore-click is-animated has-label']")