我想存储我随机生成的文本,该文本已传递到电子邮件注册页面上的文本字段。
我正在使用Selenium chromedriver和RandomWords库。
def createAccount(self):
#generate random words and opens the text file.
r = RandomWords() #generates random words using RandomWords Liberay
f = open("storeRandomWords.txt", "a")
#finds 'firstname' textfield
enter_firstname = WebDriverWait(self.driver, 20).until(expected_conditions.presence_of_element_located((By.NAME, 'firstname')))
#sends the randomly generated words to the text field
enter_firstname.send_keys(r.get_random_words(limit = 2))
我如何将'''r.get_random_words(limit = 2)'''的结果存储在文本文件中?
一种方法就是这样
def createAccount(self):
#generate random words and opens the text file.
r = RandomWords() #generates random words using RandomWords Liberay
#finds 'firstname' textfield
enter_firstname = WebDriverWait(self.driver, 20).until(expected_conditions.presence_of_element_located((By.NAME, 'firstname')))
#sends the randomly generated words to the text field
random_word = r.get_random_words(limit = 2)
enter_firstname.send_keys()
with open("test.txt", "a") as myfile:
myfile.write(random_word +"\n")