Issue
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)
Solution
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])
Answered By - Erik McKelvey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.