Contents
Installing the selenium third-party libraries
Downloading the browser drivers:
You need to put these browser drivers into the Script folder inside the Python application directory
① More than 200 Python e-books (and classic books) should be available
② The Python standard library materials (the most Chinese version)
② The project source code (forty-five interesting and reliable books). Python standard library materials (the most complete Chinese version)
③ Project source code (40-50 interesting and reliable practice projects and source code)
④ Python basic introductory, crawling, web development, big data analysis of the video (suitable for white people to learn)
⑤ Python learning roadmap (goodbye to the uninspired learning)
. Private message me01 to get a lot of Python learning resources
Every time when selenium starts chrome, chrome is clean, no plugins, no favorites, no history. This is because selenium starts a bare browser when it starts chrome to ensure the fastest efficiency, that's why it needs configuration parameters, but there are times when we need more than just a bare browser
The selenium startup configuration parameter receives the ChromeOptions class, which is created as follows:
After you create the ChromeOptions class, you add parameters, and there are a few specific ways to add parameters. There are several specific ways to add parameters, each corresponding to adding different types of configuration items
Common configuration parameters:
Other configuration item parameters
Making a headless browser
Circumventing detection
The portal detects that if it is a selenium request, it may deny access. This is also an anti-crawl mechanism
Implementing evasive detection
Note: you can only use options here to add
If you have other modules to add, note that you have to add them separately
Element positioning syntax
Common syntax:
Returns a count of all elements that meet the criteria when an element becomes an element. An array of all elements that match the condition
Controlling the size of the browser
Browser backward and forward
Refreshing
Simulating a carriage return in the search box
In WebDriver, these methods for mouse manipulation are encapsulated in the ActionChains class
The ActionChains class provides mouse manipulation methods. The ActionChains class provides common methods for mouse operations:
Syntax:
To use the keyboard events in selenium, we must first import the Keys package, and note that the package name Keys needs to be capitalized.The Keys class provides almost all of the keyboard events, including combinations such as Ctrl+A. Ctrl+C, etc.
In WebDriver, these methods are encapsulated in the ActionChains class, Ctrl+C, etc.
Usage syntax:
Other events can be accessed by looking at the source code.
Explicit wait allows Webdriver to wait for a certain condition to be met before continuing execution, or else throws a timeout exception when the maximum duration is reached.
Example:
The WebDriverWait class is an example of a wait method provided by WebDirver. WebDirver-provided wait method. It defaults to detecting whether the current page element exists every so often for a set period of time, and throws an exception if it cannot be detected for longer than the set period of time
Syntax:
Parameters:
If some elements are not immediately available, implicitly waiting tells the WebDriver to go and wait for a certain amount of time before looking for the element. The default wait time is 0 seconds, and once set, implicitly waiting sets the lifetime of the instance of the WebDriver
Cases
Syntax:
Methods inside alert
Methods for manipulating cookies with a WebDriver:
References:
Reference links:
The default wait time is 0 seconds. 773c58406bdb
Unlike adding {'Cookies':' '} to the headers, this method adds cookies one at a time in the name,value,path,domain format
Via the execute_script() method Execute JavaScripts code to move the position of the scrollbar