Search code examples
pythonpython-3.xseleniumselenium-webdriverwebdriver

By.XPATH problem in an automatic click with Selenium


I would like to automatically click on the blue logo of the likes (the one with the thumb inside), in order to open the list of those who have left the likes. I am referring to this little blue logo:

enter image description here

In the question I want to focus only on this small request, on this small click. I think I am doing it right, but surely there is something wrong. I used By.XPATH., More precisely: //*[@id="jsc_c_z"]/span[1]/span/span/div

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="jsc_c_z"]/span[1]/span/span/div'))).click()

NOTA :I've noticed that the IDs and ranges on this page look suspiciously obfuscated and so maybe they won't necessarily be the same every time. So maybe I don't think id = "jsc_c_z" that will be reliable. You may need to resort to using aria-labeld of the attribute on the target element div.

This instead is the link I would like to open https://www.facebook.com/FranzKafkaAuthor/posts/3985338151528881.

IMPORTANT: You have to enter with the Facebook login, but who does not want to do so will post a screenshot enter image description here

I hope someone can help me. Thanks


Solution

  • I solved it by myself. The solution was:

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[@class='j1lvzwm4']"))).click()