[英]How to export a list to web page text box using selenium webdriver in python?
My work here is to get data from google sheets and put those values in the webpage text box - using python我在这里的工作是从谷歌表格中获取数据并将这些值放在网页文本框中 - 使用 python
In my google sheet, I have 450 rows which are comma-separated values.在我的谷歌表中,我有 450 行是逗号分隔的值。 I need put all the 450 rows data into the webpage text box using selenium send.key().
我需要使用 selenium send.key() 将所有 450 行数据放入网页文本框中。
##getting data from google sheets.
scope = ['https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name('json',scope)
client = gspread.authorize(credentials)
workbook = client.open_by_url("https://docs.googlesheet") # using google sheet here
sheet1 = workbook.worksheet("Sheet1")
##converted sheet1 data into a dataframe called dera.
dera = gd.get_as_dataframe(sheet1, evaluate_formulas=True, skiprows=0, has_header=True)
##from dera dataframe reading 'names' column and removing null values.
del = dera[['names']].dropna()
##Converted my dataframe into list- I have read it will be easy to put list(z) values in send keys
z = del['names'].values.tolist()
Selenium code:
driver = webdriver.Chrome(executable_path="/Users/naveenbabudadla/Documents/automation/chromedriver")
driver.get("https://google.com/") # using google.com as example
driver.find_element_by_xpath("//div[text()='Maximum 5000 names'] /..//textarea").send_keys(z) ## got stuck here.
time.sleep(2)
not able to define "z" to selenium send keys correctly.无法将“z”定义为 selenium 正确发送密钥。
Can someone help me with this?有人可以帮我弄这个吗?
So let's forget about whole code before z = del['names'].values.tolist()
and assume it works, you could change del
name to some other name as del is a build in symbol in python.因此,让我们忘记
z = del['names'].values.tolist()
之前的整个代码并假设它有效,您可以将del
名称更改为其他名称,因为 del 是 python 中的内置符号。 But if it works then it wokrs.但如果它有效,那么它就可以工作。 So it seems that
z
is some list, let's say it's a list of strings then it would look like ['value1', 'value2']
.所以看起来
z
是一些列表,假设它是一个字符串列表,那么它看起来像['value1', 'value2']
。 If you want to send it to your browser as is you should change it to string with str(z)
.如果您想按原样将其发送到浏览器,则应使用
str(z)
将其更改为字符串。 Perhaps you want to send some value of your list then you chould send z[0]
.也许您想发送列表的一些值,然后您应该发送
z[0]
。 But still all of these are my quesses, you should provide exact stacktrace of your errror.但仍然所有这些都是我的问题,你应该提供你错误的确切堆栈跟踪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.