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)05/31 Report--
This article mainly introduces "how to solve the python selenium simulation click problem". In the daily operation, I believe that many people have doubts about how to solve the python selenium simulation click problem. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to solve the python selenium simulation click problem". Next, please follow the editor to study!
1. Install Google browser # download package wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb# installation package Install sudo dpkg-I-force-depends google-chrome-stable_current_amd64.deb### Segmentation with deb # # if Packet xxx is not installed appears On behalf of the dependency problem, execute the following command apt-get install-f # to re-execute sudo dpkg-I-force-depends google-chrome-stable_current_amd64.deb### partition # # to enable it to run sudo apt-get install xvfb2 without interface, Install browser driver # first get the latest version information of chromedriver LATEST=$ (wget-Q-O-http://chromedriver.storage.googleapis.com/LATEST_RELEASE)# download wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip # decompress unzip chromedriver_linux64.zip # if you don't have unzip installed, run apt install unzip# permissions to configure chmod + x chromedriver # move to sudo mv chromedriver / usr/bin/3 under the bin directory, Install selenium# to see if your system is pip3. -I indicates what source to use to download pip3 install selenium-I https://pypi.tuna.tsinghua.edu.cn/simple4, simple testing
First create the test.py file, then execute python3 test.py to see the effect
# coding=utf-8from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionschrome_opt = Options () # create parameter setting object. Chrome _ opt.add_argument ('--headless') # uninterfaced. Chrome _ opt.add_argument ('--disable-gpu') # with the above uninterfaced. Chrome _ opt.add_argument ('--window-size=1366768') # sets the window size The size of the window has an impact. Chrome _ opt.add_argument ("--no-sandbox") # runs in sandboxie mode # creates a Chrome object and passes in setting information. Browser = webdriver.Chrome (chrome_options=chrome_opt) url = "https://www.baidu.com/"browser.get(url)print(browser.page_source)browser.quit()5, sign-in program
Here I first use the Selenium of the browser plug-in to click on the export python file to modify it. The program needs to create a data.csv file and write the account password in it.
# Generated by Selenium IDEimport sysimport timefrom selenium import webdriverfrom selenium.webdriver.common.by import By# read data function userList = [] def readData (): with open ("data.csv", "r") as f: for lines in f.readlines (): data = lines.strip () .split (" ") userList.append (data) # global function def printLog (info): print ('{0} {1} '.format (time.strftime ('% Y-%m-%d% HV% MV% Shop time.localtime (time.time () Info) # sign-in class class Test: # initialize browser def _ _ init__ (self): # add Chrome-related configuration options = webdriver.ChromeOptions () # specify the device name to options.add_experimental_option ('mobileEmulation' {'deviceName':' iPhone X'}) options.add_argument ('--no-sandbox') options.add_argument ('--disable-dev-shm-usage') # options.add_argument ('--headless') self.driver = webdriver.Chrome (chrome_options=options) # = > add configuration printLog when opening the browser ("browser initialization completed") # official sign-in def signIn (self,username Password): printLog ("opening web page") self.driver.get ("http://stu.zstu.edu.cn/webroot/decision/url/mobile?origin=53fd9573-139e-4e3b-9357-4d791849ad58#/login") # Sleep Control Speed # Refresh Page self.driver.refresh () time.sleep (3) self.driver.set_window_size (800,824) self.driver.find_element (By.XPATH "/ / * [@ id='app'] / div/div [1] / div/div/div/div/div/div/div/div [2] / div [2] / div [1] / div/input") .click () self.driver.find_element (By.XPATH "/ / * [@ id='app'] / div/div [1] / div/div/div/div/div/div/div/div [2] / div [2] / div [1] / div/input") .send_keys (username) self.driver.find_element (By.XPATH, "/ / input [@ type=\ 'password\']) .click () self.driver.find_element (By.XPATH) "/ / input [@ type=\ 'password\']") .send_keys (password) time.sleep (3) self.driver.find_element (By.CSS_SELECTOR, ".r-1loqt21:nth-child (4)") .click () time.sleep (4) printLog ("login successful") # find the sign-in function module self.driver.find_element (By.CSS_SELECTOR ".r-1loqt21:nth-child (2)"). Click () time.sleep (2) printLog ("start clocking in") self.driver.find_element (By.CSS_SELECTOR, "# col_3_row_6. Css-901oao") .click () time.sleep (1) self.driver.find_element (By.XPATH "/ / div [34] / div/div/div/div"). Click () time.sleep (1) self.driver.find_element (By.CSS_SELECTOR, "# col_4_row_6 > div"). Click () time.sleep (1) self.driver.find_element (By.XPATH "/ / div [2] / div/div [2] / div/div/div/div/div"). Click () time.sleep (1) self.driver.find_element (By.CSS_SELECTOR, "# col_5_row_6 > div"). Click () time.sleep (1) self.driver.find_element (By.XPATH "/ / div [2] / div/div [6] / div/div/div"). Click () time.sleep (1) self.driver.find_element (By.CSS_SELECTOR, "# col_3_row_7. Css-1cwyjr8"). Click () self.driver.find_element (By.CSS_SELECTOR "# col_3_row_7. Css-1cwyjr8"). Send_keys ("Zhejiang University of Technology") printLog ("clocking in") # option I don't know why css positioning can't use self.driver.find_element (By.XPATH, "/ / div [10] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [12] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH) "/ / div [13] / div/div/div/div/div/div/div [2]"). Click () self.driver.find_element (By.XPATH, "/ / div [17] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [18] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH "/ / div [19] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [20] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH "/ / div [21] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [23] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [25] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH "/ / div [26] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [28] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH "/ / div [30] / div/div/div/div/div [2] / div/div"). Click () time.sleep (1) # submit self.driver.find_element (By.CSS_SELECTOR "# col_1_row_39"). Click () time.sleep (10) printLog ("sign in successfully") def quit (self): self.driver.quit () printLog ("browser exit") if _ _ name__ = ='_ main__': test = Test () readData () for i in range (len (userList)): try: test.signIn (userList [I] [0]) UserList [I] [1]) except: printLog ("sign in successfully or system bug Next ") continue test.quit () printLog (" clock in today ") sys.exit () 6, linux set scheduled task # after uploading code, set scheduled crontab-e # after opening, add the following records, which means execute 0 3 * / usr/bin/python3 / home/shawn/ezl/sign.py > / home/shawn/ezl/elog.log 2 > & restart systemctl restart cron.service7 at 3 o'clock every day, and other
The top part is opened for graduate students, and the lower part is for undergraduates.
# Generated by Selenium IDEimport sysimport timefrom selenium import webdriverfrom selenium.webdriver.common.by import By# read data function userList = [] def readData (): with open ("data.csv", "r") as f: for lines in f.readlines (): data = lines.strip () .split (" ") userList.append (data) # global function def printLog (info): print ('{0} {1} '.format (time.strftime ('% Y-%m-%d% HV% MV% Shop time.localtime (time.time () Info) # sign-in class class Test: # initialize browser def _ _ init__ (self): # add Chrome-related configuration options = webdriver.ChromeOptions () # specify the device name to options.add_experimental_option ('mobileEmulation' {'deviceName':' iPhone X'}) options.add_argument ('--no-sandbox') options.add_argument ('--disable-dev-shm-usage') options.add_argument ('--headless') self.driver = webdriver.Chrome (chrome_options=options) # = > add configuration printLog when opening the browser ("browser initialization completed") # official sign-in def signIn (self,username Password): printLog ("opening web page") self.driver.get ("http://stu.zstu.edu.cn/webroot/decision/url/mobile?origin=53fd9573-139e-4e3b-9357-4d791849ad58#/login") # Sleep Control Speed # Refresh Page self.driver.refresh () time.sleep (3) self.driver.set_window_size (800,824) self.driver.find_element (By.XPATH "/ / * [@ id='app'] / div/div [1] / div/div/div/div/div/div/div/div [2] / div [2] / div [1] / div/input") .click () self.driver.find_element (By.XPATH "/ / * [@ id='app'] / div/div [1] / div/div/div/div/div/div/div/div [2] / div [2] / div [1] / div/input") .send_keys (username) self.driver.find_element (By.XPATH, "/ / input [@ type=\ 'password\']) .click () self.driver.find_element (By.XPATH) "/ / input [@ type=\ 'password\']") .send_keys (password) time.sleep (3) self.driver.find_element (By.CSS_SELECTOR, ".r-1loqt21:nth-child (4)") .click () time.sleep (4) printLog ("login successful") # find the sign-in function module # self.driver.find_element (By.CSS_SELECTOR ".r-1loqt21:nth-child (2)") .click () self.driver.find_element (By.XPATH "/ / * [@ id='app'] / div/div [1] / div/div/div/div [1] / div/div/div/div/div/div [1] / div/div/div/div [2] / div/div/div [3] / div/div/div [5] / div/div/div [3]") .click () time.sleep (5) printLog ("start clocking in") # self.driver.find_element (By.CSS_SELECTOR "# col_3_row_6. Css-901oao") .click () self.driver.find_element (By.XPATH, "/ / * [@ id='col_1_row_11'] / span") .click () time.sleep (5) self.driver.find_element (By.XPATH "/ / div [2] / div/div/div/div/div/div/div/div/div/div/div"). Click () time.sleep (1) self.driver.find_element (By.XPATH, "/ / div [34] / div/div/div/div"). Click () time.sleep (1) self.driver.find_element (By.XPATH "/ / div [2] / div/div/div/div/div/div/div/div/div/div [2] / div"). Click () time.sleep (1) self.driver.find_element (By.XPATH, "/ / div [2] / div/div [2] / div/div/div/div/div/div"). Click () time.sleep (1) self.driver.find_element (By.XPATH "/ / div [3] / div"). Click () time.sleep (1) self.driver.find_element (By.XPATH, "/ / div [6] / div/div/div/div"). Click () time.sleep (1) self.driver.find_element (By.XPATH, "/ / input"). Click () time.sleep (1) self.driver.find_element (By.XPATH "/ / input"). Send_keys ("Zhejiang University of Technology") time.sleep (1) printLog ("clock in progress") # option I don't know why css positioning can't use self.driver.find_element (By.XPATH, "/ / div [11] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [13] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH) "/ / div [14] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [18] / div/div/div/div/div/div/div [2]"). Click () self.driver.find_element (By.XPATH, "/ / div [19] / div/div/div/div"). Click () self.driver.find_element (By.XPATH "/ / div [19] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [20] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [21] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH "/ / div [22] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [24] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [26] / div/div/div/div/div/div/div"). Click () self.driver.find_element (By.XPATH "/ / div [27] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH, "/ / div [29] / div/div/div/div/div [2] / div/div"). Click () self.driver.find_element (By.XPATH "/ / div [31] / div/div/div/div/div [2] / div/div"). Click () time.sleep (1) # submit self.driver.find_element (By.XPATH, "/ / * [@ id='col_0_row_40'] / div/div/div/div") .click () # self.driver.find_element (By.CSS_SELECTOR "# col_0_row_40. R-1loqt21 > .css-1dbjc4n"). Click () time.sleep (10) printLog ("sign in successfully") def quit (self): self.driver.quit () printLog ("browser exit") if _ _ name__ = ='_ main__': test = Test () readData () for i in range (len (userList)): try: test.signIn (userList [I] [0]) UserList [I] [1]) except: printLog ("sign in successfully or system bug Is working on the next ") continue test.quit () printLog (" clock in today ") sys.exit () so far, the study on" how to solve the click problem of python selenium simulation "is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.