2016-11-22 75 views
0

如何在頁面完全加載之前單擊頁面上的按鈕?我知道我可以使用driver.set_page_load_timeout(400)來設置超時時間,但是這個頁面需要很長時間才能加載,我不需要加載它以便繼續。在頁面完全加載之前單擊按鈕

是否有可能做這樣的事情:

time.sleep(2)   # wait a few seconds to make sure button exists 
driver.stop_loading() # or similar? 
button.click()   # navigate to next page 
+0

我被你的問題很感興趣,上了這2個鏈接:[鏈接1](http://stackoverflow.com/a/28312567/3846228)和[ LINK2](http://stackoverflow.com/questions/28702637/selenium-click-without-waiting-for-page-to-load-python)。也許他們可以幫助你。 –

回答

0

您可以按ESC鍵停止加載頁面。

在Ruby:

//Sleep 
@driver.action.send_keys(:esc).perform 
//Button click 

如果你能在python找出等效代碼它會工作。 不知道,但它應該是這樣的:

time.sleep(2) 
ActionChains(driver) \ 
    .send_keys(Keys.ESC) \ 
    .perform() 
button.click() 
相關問題