How do I insert information into the page that is in Excell

Asked

Viewed 53 times

1

Good afternoon guys, I wonder if anyone can help me ...

I am automating a page and would like to know if it is possible to use an Excell spreadsheet to popular the fields ...

for example:

Today I am using the following command below, it inserts into the element mname the Marian information, this I entered manually.

driver.find_element_by_id("mname").send_keys("mariano") 

What do I need? I need that instead of this Marian, it looks for information that is in an Excell spreadsheet, so I will use Excell as a parameter without having to touch my script

driver.find_element_by_id("mname").send_keys("Dados da coluna A2 do Excell")

Thank you very much.

2 answers

1

If you use a CSV in Excell, you can do this with direct file manipulation or with the module csv, which is part of the standard library. If you use the xlsx format, you will need a external module to read the file. There are several.

  • Thank you Cochise, I will study here and see if I have a good result ... abçs

  • Good afternoon Cochise, it worked ... thank you very much. book = xlrd.open_workbook("spreadsheet.xls") sh = book.sheet_by_index(0) I used this routine within the function.. driver.find_element_by_id("fname"). send_keys(sh.cell_value(rowx=2-1, colx=1-1))

1

import xlrd

book = xlrd.open_workbook("planilha.xls")
sh = book.sheet_by_index(0)

def test_e_cadastroI(self, mem_dc=None):
driver.find_element_by_id("fname").send_keys(sh.cell_value(rowx=2-1, colx=1-1))

......

  • 4

    Could you explain your code? Even if it seems trivial, not all users will be able to understand it. A text explanation of the logic of your solution will only bring improvements to your answer.

  • import xlrd --> * Importing the xlrd Library is about reading external & #Xa; book = xlrd.open_workbook("spreadsheet.xls") --> I created a variable informing her the file I am using, it is necessary that the file is in the same folder where the . py is located sh = book.sheet_by_index(0) def test_e_cadastroI(self, mem_dc=None): driver.find_element_by_id("fname"). send_keys(sh.cell_value(rowx=2-1, colx=1-1)) -> rowx and colx refer to rows and columns respectively.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.