简体   繁体   English

如何使用 python 中的 selenium webdriver 将列表导出到 web 页面文本框?

[英]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.

相关问题 如何在 python 中使用 selenium webdriver 滚动 web 页面? - How can I scroll a web page using selenium webdriver in python? 在 python 中使用 selenium webdriver 滚动 web 页面 - Scroll a web page using selenium webdriver in python 使用Selenium Python WebDriver滚动网页 - Scrolling web page using selenium python webdriver 在selenium webdriver中切换到web对话框:Python - Switch to web dialog box in selenium webdriver: Python 如何从随机文本框生成器复制+粘贴? 使用 python,webdriver selenium? - How to copy + paste from a random text box generator? Using python, webdriver selenium? 我可以在python中使用Selenium Webdriver滚动网页吗 - can I scroll a web page using selenium webdriver in python 在 python 中使用 selenium webdriver 滚动 web 页面并无限加载 - Scroll a web page using selenium webdriver in python with infinite loading 如何在python中使用Selenium Webdriver滚动网页以抽搐? - How can I scroll a web page using selenium webdriver in python, for twitch? 如何在python中使用Selenium Webdriver滚动动态网页的特定部分? - How can I scroll a particular section of a dynamic web page using selenium webdriver in python? 如何在 python 中使用 selenium webdriver 无限滚动 web 页面 - How can I infinite-scroll a web page using selenium webdriver in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM