Tell me why this does not end up with a timeout error (selenium 2 webdriver)?

2024/10/3 8:29:24
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWaitbrowser = webdriver.Firefox()browser.get("http://testsite.com")element = WebDriverWait(browser, 10).until(lambda browser : browser.find_element_by_id("element"))element.click() # it actually goes to page http://testsite.com/test-page.htmlprint "Just clicked! And I'm expecting timeout error!"new_element = WebDriverWait(browser, 0.1).until(lambda browser : browser.find_element_by_id("element"))print "Too bad there's no timeout error, why?!"

OK, as you can see even I set wait time to 0.1 sec there's still no timeout exception thrown. When element.click() executed it does not block till the whole page loads up and that's why Just clicked! And I'm expecting timeout error! showed up, and to my surprise new_element = WebDriverWait(browser, 0.1).until(lambda browser : browser.find_element_by_id("element")) wait till the whole page loads up. And if you use implicit waits, you get the same result.

My point is, sometimes after you click an element it might take up to even hours for a page to load up because of a bad proxy, and you obviously DO NOT want to wait that long, what you want is a timeout exception. In this case how would you make it work?

Answer

Clicks have an implicit wait built into them to wait for when the page is loaded. There is work, currently complete in FirefoxDriver only, that allows you to set how long Selenium should wait for a page to load.

This will probably be in Selenium 2.22 for Python and then your test case will likely fail once that is set

https://en.xdnf.cn/q/70744.html

Related Q&A

PEP 8: comparison to True should be if cond is True: or if cond:

PyCharm is throwing a warning when I do np.where(temp == True)My full code:from numpy import where, arraya = array([[0.4682], [0.5318]]) b = array([[0.29828851, 0., 0.28676873, 0., 0., 0., 0., 0.288014…

Getting the title of youtube video in pytube3?

I am trying to build an app to download YouTube videos in python using pytube3. But I am unable to retrieve the title of the video. Here goes my code: from pytube import YouTube yt = YouTube(link) prin…

pandas - concat with columns of same categories turns to object

I want to concatenate two dataframes with category-type columns, by first adding the missing categories to each column.df = pd.DataFrame({"a": pd.Categorical(["foo", "foo"…

Python convert Excel File (xls or xlsx) to/from ODS

Ive been scouring the net to find a Python library or tool that can converts an Excel file to/from ODS format, but havent been able to come across anything. I need the ability to input and output data …

Select pandas frame rows based on two columns values

I wish to select some specific rows based on two column values. For example:d = {user : [1., 2., 3., 4] ,item : [5., 6., 7., 8.],f1 : [9., 16., 17., 18.], f2:[4,5,6,5], f3:[4,5,5,8]} df = pd.DataFrame(…

Using scipy sparse matrices to solve system of equations

This is a follow up to How to set up and solve simultaneous equations in python but I feel deserves its own reputation points for any answer.For a fixed integer n, I have a set of 2(n-1) simultaneous e…

Segmentation Fault in Pandas read_csv

I have Python 2.7.5 on Os X 10.9 with Pandas version 0.12.0-943-gaef5061. When I download this train.csv file and run read_csv, I get Segmentation Fault 11. I have experimented with the file encoding…

Multiple subprocesses with timeouts

Im using a recipe that relies on SIGALRM to set alarm interrupt -- Using module subprocess with timeoutThe problem is that I have more than one Python script using signal.ALARM process to set time-outs…

what is the difference between tfidf vectorizer and tfidf transformer

I know that the formula for tfidf vectorizer is Count of word/Total count * log(Number of documents / no.of documents where word is present)I saw theres tfidf transformer in the scikit learn and I just…

Use Pandas string method contains on a Series containing lists of strings

Given a simple Pandas Series that contains some strings which can consist of more than one sentence:In: import pandas as pd s = pd.Series([This is a long text. It has multiple sentences.,Do you see? M…