How to make Selenium WebDriver not to wait for whole page to load

I am using python 2.7 with Selenium webdriver for Firefox and I have a problem I can't solve or find solved on the internet. My task is to open around 10k web pages (adsl router web interfaces - via ip address) and upload new firmware. I wrote the code but in order to finish it I must learn how to make selenium webdriver not to wait for page load like forever, but to wait for 2 minutes(it is time needed for new firmware to upload) and then proceed to next step. I thought I let it wait for forever (wait for router to reconnect - much slower but doable by me without help) but the catch is when I click upload button it takes 2 minutes of uploading new firmware, then router reboots to apply changes (takes less then 2 minutes), then tries to connect (around 10 seconds) and even then if it gets some other IP it will never load and my program wait for forever. So, I want to skip all of that and I want program to proceed to next router after first 2 minutes. Can it be done? I read something about "pageLoadingStrategy" but I couldn't understand how to use it. Please write me if it is not understandable, because English is not my native language. Below you can see the code sample, after button.submit() it should wait for 2 minutes and proceed and not wait forever:

def firmware_upload(): global ip br.get("http://"+ip+"/upload.html") button = br.find_element_by_xpath('//input[@type="file" and @name="filename"]') button.send_keys("/home/djura/Downloads/KW5815A_update_140417") button.submit() print ("Odradjen UPDATE SOFTWARE-a!") return

Answer1:

The problem is probably because you are using button.submit, which if I'm not mistaken waits for the return of the action. So instead you should find the <strong>actual submit button</strong> and click on it using click, e.g.

submit_button = br.find_element_by_id('SUBMIT_BTN_ID') submit_button.click()

P.S. the fact that in your example code your button variable actually refers to an input element is misleading.

Answer2:

see if this works.

try { br.manage().timeouts().pageLoadTimeout(2, TimeUnit.MINUTES); global ip br.get("http://"+ip+"/upload.html") button = br.find_element_by_xpath('//input[@type="file" and @name="filename"]') button.send_keys("/home/djura/Downloads/KW5815A_update_140417") button.submit() print ("Odradjen UPDATE SOFTWARE-a!") return } catch(TimeoutException e) { print("2min over"); }

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:How to make Selenium WebDriver not to wait for whole page to load