我正在尝试通过将图像路径存储在 .CSV 文件中并通过读取来上传图像csv.reader
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
class Browse(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "http://google.com/"
filename = 'test.csv'
line_number = 1
with open(filename, 'rb') as f:
mycsv = csv.reader(f)
mycsv = list(mycsv)
self.cityname=mycsv[line_number][0]
self.username=mycsv[line_number][1]
self.password=mycsv[line_number][2]
...
self.photo=mycsv[line_number][10]
self.verificationErrors = []
def test_browse(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_elements_by_xpath("//div[@class='addmore']/form/input[3]").send_keys(self.photo)#here is where I am trying to input the photo
在 CSV 文件中
我有一个像
|__________photo__________|
| /path to the image/ |
那么这会奏效吗?我试过了。但我失败了。