Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use Selenium IDE

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to install and use Selenium IDE, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Today you will learn to use a very useful browser plug-in, Selenium IDE, for website testing and automation, using Google browser as a test.

The plug-in can be downloaded from:

Https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd

We click add to chrome to complete the installation of the plug-in:

After the plug-in is installed, a se icon appears in the navigation bar:

Clicking on the icon will bring up a dialog box that lets us choose how to create the project:

Here we select the first Record a new test in a new project (create a new project and record a new test) and enter the project name taobao-serach (using Taobao as the test URL):

After clicking ok, enter the URL you want to monitor:

Click START RECORDING to start recording, and the Taobao web page will automatically open and a record mark will appear:

After clicking the red stop recording button at the top right of the pop-up IDE, the recording process of all actions will appear in the middle:

Click Untitled in the left area of the figure above to name the test case hjc element search:

Let's take a look at the definition of the basic operation button in IDE:

Click the test case on the left to export the use case:

Here we export the pytest use case for python:

A python file named test_hjchelmentsearch.py is generated:

The specific code is as follows:

# Generated by Selenium IDEimport pytestimport timeimport jsonfrom selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.support import expected_conditionsfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.common.keys import Keys

Class TestHjchelmentsearch (): def setup_method (self, method): self.driver = webdriver.Chrome ('chromedriver.exe') self.vars = {} def teardown_method (self, method): self.driver.quit () def wait_for_window (self Timeout = 2): time.sleep (round (timeout / 1000)) wh_now = self.driver.window_handles wh_then = self.vars ["window_handles"] if len (wh_now) > len (wh_then): return set (wh_now) .difference (set (wh_then)). Pop () def test_hjchelmentsearch (self): self.driver.get ("https://www.taobao.com/") self.driver.set_window_size (1382) Self.driver.find_element (By.ID, "Q"). Send_keys (Keys.DOWN) self.driver.find_element (By.ID, "Q"). Send_keys ("hjc helmet") self.driver.find_element (By.ID, "Q"). Send_keys (Keys.ENTER) self.vars ["window_handles"] = self.driver.window_handles self.driver.find_element (By.ID) "J_Itemlist_Pic_42600889855") .click () self.vars ["win7263"] = self.wait_for_window (2000) self.vars ["root"] = self.driver.current_window_handle self.driver.switch_to.window (self.vars ["win7263"]) self.driver.execute_script ("window.scrollTo (0Mel78)") self.driver.find_element (By.CSS_SELECTOR "li:nth-child (8) > a > span". Click () element = self.driver.find_element (By.CSS_SELECTOR, ".tb-img > li:nth-child (6) span") actions = ActionChains (driver) actions.move_to_element (element). Perform () element = self.driver.find_element (By.CSS_SELECTOR, "body") actions = ActionChains (driver) actions.move_to_element (element, 0 0) .perform () element = self.driver.find_element (By.CSS_SELECTOR, ".tb-prop:nth-child (1) li:nth-child (6) span") actions = ActionChains (driver) actions.move_to_element (element). Perform () self.driver.find_element (By.CSS_SELECTOR ".tb-prop:nth-child (1) li:nth-child (6) span". Click () element = self.driver.find_element (By.CSS_SELECTOR, "body") actions = ActionChains (driver) actions.move_to_element (element, 0,0). Perform () self.driver.close () self.driver.switch_to.window (self.vars ["root"]) self.driver.close ()

# the following is the initialization running code hjc = TestHjchelmentsearch () hjc.setup_method (None) hjc.test_hjchelmentsearch () hjc.teardown_method () added by myself

The following code can be run as a test case.

On how to install and use Selenium IDE to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report