File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # This program illustrates a technique that can be used on pages that have
2
+ # a captcha.
3
+ # A Captha input can never by completely automated via Selenium. Usual workaround
4
+ # is to sleep for some time to allow the user (usually the Tester) to enter captcha
5
+ # text in input field.
6
+
7
+ # But in this example we are using WebDriverWait to allow the tester enough time to
8
+ # manually enter the captcha text, but as soon as the captcha is entered, the test can
9
+ # proceed. This is better than time.sleep()
10
+
11
+ from selenium import webdriver
12
+ from selenium .webdriver .common .keys import Keys
13
+ from selenium .webdriver .support .ui import WebDriverWait
14
+
15
+ driver = webdriver .Firefox ()
16
+ # This opens up contact trainer page on http://hadoopbigdatatutorial.com/
17
+ driver .get ("http://hadoopbigdatatutorial.com/home/contact_trainer/hadoop-development" )
18
+
19
+ def check_captcha_length (driver ):
20
+ """
21
+ This function finds the captcha INPUT element and
22
+ returns true when length of input text entered
23
+ is greater than 2 characters.
24
+ """
25
+ elem = driver .find_element_by_css_selector ("input.captcha_input[name='userCaptcha']" )
26
+ return len (elem .get_attribute ('value' )) > 2
27
+
28
+ # return true if captcha input is filled with a text of length more than 2 in 30 seconds
29
+ result = WebDriverWait (driver , 30 ).until (check_captcha_length )
30
+
31
+ # print title of the webpage
32
+ print (driver .title )
33
+ driver .close ()
You can’t perform that action at this time.
0 commit comments