1

I want to call multiple files by importing a text file(or csv?) and run selenium tests over until all the inputs are finished. Normally, browser would just close after just running one.

Say, I have input below in a text file. I have to replace driver.get portion and select by visible text portion with below from text file.

sampletest-x1
sampletest-x2
sampletest-x3
sampletest-x4 

Selenium

driver = webdriver.Firefox()
driver.get("http://username:password@1.1.1.1:80/sampletest-x1")
select = Select(driver.find_element_by_id('ele_id'))
select.select_by_visible_text('sampletest-x1')
driver.close();

1 Answers1

1

If all you need to do is test for existence, this should work:

driver = webdriver.Firefox()

with open('file.txt') as f:
   for line in f:
       driver.get("http://username:password@1.1.1.1:80/" + line)
       select = Select(driver.find_element_by_id('ele_id'))
       select.select_by_visible_text(line)

driver.quit()

You shouldn't be catching/handling errors, so I've left that out.

See also: How should I read a file line-by-line in Python?

Community
  • 1
  • 1
Andrew Regan
  • 5,087
  • 6
  • 37
  • 73