How do I send a random line from one file?
with open('names.txt') as f:
lines = f.readlines()
for line in lines:
self.driver.find_element_by_xpath("//input[@type='text']").send_keys(line)
CodePudding user response:
You need to generate a random number up to the number of lines, and send the line at that index:
import random
with open('names.txt') as f:
lines = f.readlines()
i = random.randrange(len(lines))
self.driver.find_element_by_xpath("//input[@type='text']").send_keys(lines[i])