In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how python automates testing selenium and executes js scripts. I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.
WebDriver has two methods to execute JavaScript scripts.
(1) synchronous execution: execute_script
(2) Asynchronous execution: execute_async_script
From selenium import webdriverfrom time import sleepclass TestScriptss (object): def setup (self): self.driver = webdriver.Chrome () self.driver.get (http://www.baidu.com) # execute js prompt box And click def test_scripts (self): self.driver.execute_script ("alert ('test')") sleep (2) self.driver.switch_to.alert.accept () self.driver.quit () # execute the script to get the current page title def test_scripts (self): js = "return document.title" title = self.driver.execute _ script (js) print (title) sleep (2) self.driver.quit () # format text box def test_format (self): js = 'var Q = document.getElementById ("kw") Q.style.border = "10px solid red" 'self.driver.execute_script (js) sleep (5) self.driver.quit () # realize page scrolling through script def test_scroll (self): self.driver.find_element_by_id (' kw'). Send_keys ('selenium test') self.driver.find_element_by_id (' su') .click () sleep (2) # search results page scroll js = 'window.scrollTo (0) Document.body.scrollHeight)'# synchronous execution self.driver.execute_script (js) # Asynchronous execution # self.driver.execute_async_script (js) sleep (2) self.driver.quit () these are all the contents of the article "how python automates testing selenium executes js scripts" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.