Test—–selenuim webDriver

Article directory 1. Page navigation 2. Element positioning 3. Browser operation 4. Get element information 5. Mouse operation 6. Keyboard operation 7. Element waiting 8. Drop-down box 9. Pop-up box 10.Scroll bar 11.frame processing 12.Verification code processing (cookie) 1. Page navigation First, import the corresponding package: from selenium import webdriver Then instantiate: driver = webdriver.Edge() […]

Use webdriver-manager to solve the problem of automation failure caused by mismatch between browser and driver

1.Foreword WhenweuseSeleniumforUIautomatedtesting,theautomatedtestoftencannotbeexecutedbecausethebrowserdriverdoesnotmatchthebrowserversion.Weneedtomanuallydownloadthecorrespondingdriverversionandreplacetheoriginaldriver.WemayalsoencounterWhentestingacrossoperatingsystems,andafterthebrowserisautomaticallyupgraded,itwillalsocausemismatchwiththedriver. Inordertosolvethisproblem,youcanusewebdriver-manager,whichcanhelpusautomaticallyidentifythesysteminformationandcorrespondingbrowserinformationinthecurrentrunningenvironment,andautomaticallydownloadthecorrespondingbrowserdriver. 2.Introduction Thewebdriver-managerlibraryprovidesawaytoautomaticallymanagedifferentbrowserdrivers. Themainideaistosimplifythemanagementofbinarydriversfordifferentbrowsers. Currentlysupports: ChromeDriver EdgeChromiumDriver GeckoDriver IEDriver OperaDriver Install: pipinstallwebdriver_manager 3.Example Originalcode: #!/usr/bin/envpython #-*-coding:utf-8-*- fromseleniumimportwebdriver driver=webdriver.Chrome() driver.get(‘https://www.baidu.com/’) Afterrunning,anerrorisreportedanditisfoundthatthisversionofChromeDriverdoesnotmatchthecurrentbrowserversionandcannotbeexecuted. Updatethecode(importwebdriver-manager,runthescript,webdriver-managerwillcheckthecurrentlyusedbrowserversionandautomaticallydownload/updatethematchingbrowserdriver,sothatthebrowserversionanddriverwillalwaysmatcheachother.) #!/usr/bin/envpython #-*-coding:utf-8-*- fromseleniumimportwebdriver fromwebdriver_manager.chromeimportChromeDriverManager driver=webdriver.Chrome(executable_path=ChromeDriverManager().install()) driver.get(‘https://www.baidu.com/’) 4.More TheauthorusesSelenium3intheexample,andwebdriver-manageralsosupportsSelenium4. 1.Chrome #selenium3 fromseleniumimportwebdriver fromwebdriver_manager.chromeimportChromeDriverManager driver=webdriver.Chrome(ChromeDriverManager().install()) #selenium4 fromseleniumimportwebdriver fromselenium.webdriver.chrome.serviceimportServiceasChromeService fromwebdriver_manager.chromeimportChromeDriverManager driver=webdriver.Chrome(service=ChromeService(ChromeDriverManager().install())) 2.Chromium #selenium3 fromseleniumimportwebdriver fromwebdriver_manager.chromeimportChromeDriverManager fromwebdriver_manager.core.utilsimportChromeType driver=webdriver.Chrome(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()) #selenium4 fromseleniumimportwebdriver fromselenium.webdriver.chrome.serviceimportServiceasChromiumService fromwebdriver_manager.chromeimportChromeDriverManager fromwebdriver_manager.core.utilsimportChromeType driver=webdriver.Chrome(service=ChromiumService(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install())) 3.Brave #selenium3 […]

Java Selenium WebDriver web page filling

1. Windows environment installation and configuration 1. Install chrome browser In the “About chrome” interface, check the browser version number 2. Download chromeDriver Download the corresponding version of the driver at https://registry.npmmirror.com/binary.html?path=chromedriver/ (if the browser version is too new, it is recommended to download the closest version). Unzip the downloaded compressed package, and remember the […]