First of all, choose an editor, we choose Sublime Text here
>ctrl+b as a shortcut to run the current script
Ii. Writing code
1 #Coding==utf-82 fromSeleniumImportWebdriver3 fromTimeImportSleep4 5Driver=Webdriver. Chrome ()6Driver.get ("http://www.baidu.com")7 #driver.get ("http://m.mail.10086.cn")8 9 Print("Browser Maximization")TenDriver.maximize_window ()#maximize the browser display One " " A #参数数字为像素点, when testing a phone screen, it is necessary to set the size of the browser to the size of the phone screen - print ("Set browser width 480, height 800 display") - driver.set_window_size (480,800) #400代表宽度, 800 stands for height the " " -Driver.find_element_by_link_text (U"News"). Click () - -Sleep (2) + #Visit the News page -First_url="http://news.baidu.com" + Print("Back to %s"%(First_url)) A Driver.back () atSleep (2) - - #forward to News page -Second_url="http://news.baidu.com" - Print("forward to%s"%(Second_url)) - Driver.forward () inSleep (2)
"The insect teacher Speaks Selenium+python" third: Operation Test object