0

I am trying to make an instagram bot to upload images / make posts. But when I try to select the upload button on the pop-up window using selenium it doesn't recognize the element.

I've tried to change windowHandles and that doesn't work. I've tried referencing it as an alert and that also won't work. I'm selecting the item using the xpath and usually selenium will instead interact with an item on the underlying page instead of the open pop-up window

chooseFileButton = ig.driver.find_element(by=By.XPATH, value="//button[contains(text(), 'Select from computer')]")
chooseFileButton.send_keys("data/images/img7.png")

I attached an image to show what I mean.

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
torin
  • 21
  • 5

1 Answers1

0

You were close enough. To locate the element Select From Computer on Instagram page you can use either of the following locator strategies:

  • Using XPATH and text():

    chooseFileButton = ig.driver.find_element(by=By.XPATH, value="//button[text()='Select From Computer']")
    
  • Using XPATH and contains():

    chooseFileButton = ig.driver.find_element(by=By.XPATH, value="//button[contains(., 'Select From Computer')]")
    

Snapshot:

selectFromComputer

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks for the quick response! It still doesn't work; it says the element does not exist. Even with a wait and a time.sleep. – torin Feb 06 '23 at 23:33