如何使用Selenium(mac)在对话框中选择图片

时间:2017-11-05 02:47:27

标签: python python-3.x selenium

我正在尝试使用Python和Selenium在Craigslist中自动执行任务。一切都很顺利,直到我不得不“添加图片”。我编写代码点击“添加图片”按钮,它打开了一个对话框(我认为这就是所谓的)。我想选择2个图像,然后单击“打开”按钮,但我不知道如何为它编写代码。我在网上看了几个例子,但没有真正对我说话。

下面是对话框的屏幕截图,蓝色突出显示我想要选择的图片:

Craiglist Picture

此外,这是我的代码:

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()

0 个答案:

没有答案