Python 3.x 使用Selenium和Python3为文本添加唯一的时间戳
我想我会找到一个简单的答案,但到目前为止,运气不好 我正在创建自动通过注册表格,为此,我理想地需要发送一些独特的文本。我在想名字+时间戳之类的东西(就像Ghost Inspector上的able一样)Python 3.x 使用Selenium和Python3为文本添加唯一的时间戳,python-3.x,selenium,selenium-webdriver,webdriver,strftime,Python 3.x,Selenium,Selenium Webdriver,Webdriver,Strftime,我想我会找到一个简单的答案,但到目前为止,运气不好 我正在创建自动通过注册表格,为此,我理想地需要发送一些独特的文本。我在想名字+时间戳之类的东西(就像Ghost Inspector上的able一样) 目前,我还可以在我的代码中每次写一个快速唯一的名称(使用send.keys(“”)),只是想看看是否有办法真正省去这个小麻烦。您可以使用此代码生成随机字符串,然后将其发送到sendKeys(“”命令) import string import random def random_string(le
目前,我还可以在我的代码中每次写一个快速唯一的名称(使用send.keys(“”)),只是想看看是否有办法真正省去这个小麻烦。您可以使用此代码生成随机字符串,然后将其发送到
sendKeys(“”
命令)
import string
import random
def random_string(length):
return ''.join(random.choice(string.ascii_letters) for m in range(length))
print random_string(10)
print random_string(5)
如果要使用UUID:
import uuid
id = uuid.uuid1()
print (id.hex) // for hex representation
print (id.int)
如果要使用时间戳,则可以使用以下代码:
import datetime
print('Date now: %s' % datetime.datetime.now())
以下是参考链接:要向文本添加唯一的时间戳,您可以使用模块中的Python方法,如下所示:
- 代码块:
from selenium import webdriver from time import gmtime, strftime options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument('disable-infobars') driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe') driver.get("http://www.google.com") driver.find_element_by_name("q").send_keys("James Stott{}".format(strftime("%Y-%m-%d %H:%M:%S", gmtime())))
- 浏览器快照:
谢谢。正是我想要的