Python Selenium Cant Find The Add Photo And Video Button Element On Facebook
Im trying to upload an image to facebook and im unable to click on the Add photo and video button. When im looking at the html this is the element im trying to click:
Solution 1:
Facebook is built through ReactJS so to click()
on the element you need to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:
Using
css_selector
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[aria-label='Add Photo or Video'][name^='composer_photo'][data-testid='media-sprout']"))).click()
Using
xpath
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@aria-label='Add Photo or Video' and starts-with(@name, 'composer_photo')][@data-testid='media-sprout']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.uiimportWebDriverWaitfrom selenium.webdriver.common.byimportByfrom selenium.webdriver.supportimport expected_conditions asEC
Solution 2:
your id might getting change everytime.Try use xpath with attribute.
However use webdriverwait
and element_to_be_clickable
to click on that.
from selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,'//input[@aria-label="Add Photo or Video"][@name="composer_photo[]"]'))).click()
Solution 3:
Thanks guys i was able to find it by the class name trough the parent
driver.find_element_by_class_name("_3jk")
Post a Comment for "Python Selenium Cant Find The Add Photo And Video Button Element On Facebook"