在循环的第一个执行期间,正在输入getTotal的数据“ actions.send_keys(Keys.CLEAR).send_keys(getTotal()).send_keys(Keys.ENTER).perform()”可以,但是在下一个循环执行周期将在输入当前值之前重新输入getTotal的先前数据。
for i in range( 1000 ):
try :
# Enter the answer
answer = driver.find_element_by_xpath( "//div[@class='_1mf _1mj']" )
# driver.find_element(By.XPATH,"//div[@class='_1mf _1mj']").send_keys(ans)
answer = actions.send_keys( Keys.CLEAR ).send_keys( getTotal() ).send_keys( Keys.ENTER ).perform()
print( 'Answer has been entered' )
time.sleep( 15 )
except TimeoutError as e:
print( e )
print( "Element has not found" )
driver.quit()