这几乎是所有代码
code = '123456789123456798abcdefghilmnopqrstuvz...' # very long code (~60 chars)
chrome_options = Options()
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("http://localhost/mytest")
wait = WebDriverWait(driver, 10)
text = re.search('lorem ipsum \s\((.+?)\)', driver.page_source) # extract text between parentheses from the whole page
ActionChains(driver)\
.send_keys(Keys.TAB)\
.send_keys(code)\
.send_keys(Keys.TAB)\
.send_keys(text.group(1))\
.send_keys(Keys.TAB)\
.send_keys(Keys.SPACE)\
.perform()
即使字符串code
非常长,它看起来send_keys
总能正常工作。
通常text.group(1)
是4-5个字符长的字符串,但send_keys
随机似乎丢失了一些字符。