Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - Selenium Webdriver stuck when find_element method called with a non-existed widget

I'm trying to test with selenium webdriver. My version of selenium is 2.33 and the browser is Firefox. The scripting language is python

Now when I call the method find_element_by_xpath(blabla) If the widget does not exist. The program just gets stuck there with no exception shown. It's just stuck. By the way I have tried find_element_by_id, find_element_by_name, find_elements and changed Firefox to 3.5, 14.0, 21.0, 22.0. The problem always shows up.

Anybody ever got this problem? I just want an exception not just getting stuck. Help...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

find_element_* raises selenium.common.exceptions.NoSuchElementException if element is not found.

find_elements_* return empty list if element is not found.

Both functions does not stuck.

According to Selenium documentation:

4.1. Locating by Id

Use this when you know id attribute of an element. With this strategy, the first element with the id attribute value matching the location will be returned. If no element has a matching id attribute, a NoSuchElementException will be raised.

...

4.2. Locating by Name

Use this when you know name attribute of an element. With this strategy, the first element with the name attribute value matching the location will be returned. If no element has a matching name attribute, a NoSuchElementException will be raised.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...