简体   繁体   中英

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

In my google sheet, I have 450 rows which are comma-separated values. I need put all the 450 rows data into the webpage text box using selenium send.key().

##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.

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. 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'] . If you want to send it to your browser as is you should change it to string with str(z) . Perhaps you want to send some value of your list then you chould send z[0] . But still all of these are my quesses, you should provide exact stacktrace of your errror.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM