Selenium sendKeys发送部分值

时间:2018-06-13 18:23:19

标签: python selenium

这几乎是所有代码

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随机似乎丢失了一些字符。

0 个答案:

没有答案