1

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
JLJ
  • 77
  • 6
  • To debug you can probably add code to take screenshot and check what is getting rendered in case of RPI. Also you haven't added any particular error your script is throwing. – Ishan Nov 18 '19 at 09:06
  • The script itself isn't giving any errors, it is just returning an empty array as it is not finding the specific element. – JLJ Nov 18 '19 at 10:09

1 Answers1

1

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']")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for your solution! I shall try it when I get home and report back. Do you have any insight as to why the performance would be different in this case between a pc and RPI? thanks for your help. – JLJ Nov 18 '19 at 10:11
  • @JLJ I don't think this particular line of code will have any performance impact but it's all about writing optimized locators. _Performance_ of your entire _Test Suite_ is a bigger picture and yes there are best practices. – undetected Selenium Nov 18 '19 at 10:16
  • I implemented using css selector and it now works! thanks. – JLJ Nov 18 '19 at 19:34