I'm trying to automate tasks in Craigslist using Python and Selenium. Everything was going ok until I had to "Add Image". I wrote code to click the "Add Image" button and it opened up a dialogue box (I think that's what it's called). I want to select 2 images and click the "Open" button but I don't know how to write the code for it. I saw a few examples online but nothing really spoke to me.
Below is a screenshot of the dialogue box and highlighted in blue are the images I'd like to select:
Also, here is my code:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://dallas.craigslist.org/")
# Click on "computer" link
driver.find_element_by_link_text("computer").click()
#Post
driver.find_element_by_link_text("post").click()
#Gig Offered radion button
driver.find_element_by_xpath("/html/body/article/section/form/ul/li[2]/label/span[2]").click()
# I want to hire someone
driver.find_element_by_xpath("/html/body/article/section/form/label[1]").click()
#Please choose a category: Computer Gigs"
driver.find_element_by_xpath("//*[@id='picker']/ul/li[1]/label/span[2]").click()
# Choose the location
driver.find_element_by_xpath("/html/body/article/section/form/ul/li[1]/label/input").click()
# Enter text
# Enter Posting Title
posting = driver.find_element_by_id("PostingTitle")
posting.send_keys("[SEEKING] Parents with Kids who Play Sports. Save Money on College!")
# Enter Location
area = driver.find_element_by_id("GeographicArea")
area.send_keys("Dallas Area")
# Enter Zip Code
zipcode = driver.find_element_by_id("postal_code")
zipcode.send_keys("75001")
# Enter Body
body = driver.find_element_by_id("PostingBody")
body.send_keys("this is a test)
# No Pay
driver.find_element_by_xpath("//*[@id='vol_label']/input").click()
#From Email
fromemail = driver.find_element_by_id("FromEMail")
fromemail.send_keys("foo@gmail.com")
# Confirm Email
confirmemail = driver.find_element_by_id("ConfirmEMail")
confirmemail.send_keys("foo@gmail.com")
# Maps
driver.find_element_by_id("wantamap").click()
# Click Continue
driver.find_element_by_xpath("//*[@id='postingForm']/div/button").click()
# Add Images
driver.find_element_by_id("plupload").click()