Python + Selenium notes (2): configure the Google + IE environment and pythonselenium
#Sometimes you may need to access a foreign website to download materials or tools. In this case, various problems may occur, such as Google's failure to display man-machine verification and Website access failure. We recommend that you use a FQ software.
Download the free version. Download and install it directly.
Http://
This article is mainly for you to introduce the Python+selenium automation to achieve paging pagination processing method, with a certain reference value, interested in small partners can refer to
Scene
For pagination, we are most interested in the following information
How many pages are there in totalHow many pages are you currently on?Can I have a previous page and a next page?
Code
The following c
Python + Selenium automate pagination processing and seleniumpagination
Scenario
For paging, we are most interested in the following information:
Total number of pagesCurrent pageWhether the previous page or next page can be used
Code
The following code obtains the total number of pages and the current page number, and redirects to the specified page number.
# Coding: utf-8from
Selenium is an automated testing framework for UI-layer web-side, and is currently the most popular automated testing framework on the market.Let's start with the basics:1 fromSelenium Import Webdriver2 Import Time3 4Driver =Webdriver. Firefox ()5 6 #浏览器最大化7 # Driver.maximize_window ()8 #自定义浏览器的宽和高9# driver.set_window_size (666,555)Ten OneURL ="http://www.cnblogs.com/hanxiaobei/" ADriver.Get(URL) -Time.sleep (5) -Print"website Title", Driver.title)
First, the browser to maximizeSecond, set the browser resolution sizeThird, print the page titleFour, print the URLV. Control browser forward or backward#!/usr/bin/env python#-*-Coding:utf-8-*-From selenium import WebdriverImport timeBrowser = Webdriver. Firefox ()#浏览器最大化Browser.maximize_window ()#设置浏览器分辨率大小Browser.set_window_size (800,600)#访问百度首页Index_url = "Http://www.baidu.com"Print browser.title# Printi
Installing Selenium with PipDownload Chromedriver, add in Path#-*-coding:utf-8-*- fromSeleniumImportWebdriver fromSelenium.common.exceptionsImporttimeoutexception fromSelenium.webdriver.support.uiImportWebdriverwait#available since 2.4.0Import Time#Create A new instance of the browser driverDriver = Webdriver. Chrome ()##可以替换为IE (), Firefox () Chrome ( ) #go to the Google home pageDriver.get ("https://www.google.com") #find the element that's na
Don't say much nonsense, just say the point:At the beginning of the time, agent IP, head information pool, have been done, using SELENIUM+PHANTOMJS to get JS dynamic loading of the source codeAt first very good, can come out of the dynamic load after the source code, but after several runs, the computer a little lag (estimated that the storage is too small), the source will not get, the data returnedIt's all empty data, so it's all wrong.Make sure to
not a problem, directly on the browser to execute, but also to perform successfully. Results various attempts jquery Different click Method, finally cannot solve. Later changed to JS Grammar is done.Encounter problems1. When executing the jquery script, error:
Selenium.common.exceptions.WebDriverException:Message:unknown Error: $ is not defined
2. Some of the following methods have been tried in the future without effect:
Sleep time is a bit longer, so the page is loaded
PageObject is one of the best design patterns for the Selenium Automation test project development practice, which mainly embodies the encapsulation of interface interaction details, which allows the test case to focus more on the business than on the interface details, thus improving the readability of the test case.1. Understanding PageObjectThe advantages of the PageObject design pattern are as follows:* Reduce duplication of code* Improve the read
Unlike the "HTML element Positioning " Article, this article mainly records the various control operations of selenium. 1. Modify page element properties.Requirements Scenario: Take the Solution: It seems that Webdriver does not change the original information of the page, but it provides an interface that can manipulate JavaScript scripts, which can modify the attributes of the elements smoothly.Specific implementations: driver.execute_script (script
(Diver.page_source,'lxml') Items=soup.find ('Div',{'class':'con_reference'}). Find_all ('Li') forIinchItems:PrintI.find ('a'). Get_text ()#Close Web pageDiver.close ()Attention:Code in red callout, I because of this mistake, got a half dayI encountered a problem, each time the first crawl, click the event does not respond, use breakpoints to see the discovery again, the back can be, this I do not know why this is the caseChrome Click event does not executeIf you do not want to see the browser a
Reptiles often use this, found a more useful methodOriginal link: http://blog.csdn.net/u012189659/article/details/36391837Background: Selenium+python is in the learning phase, after the functional implementation began to organize the code before writing, suddenly found a function did not make judgments, such as, click "Please login", you need to determine whether this pop-up box does not play, so you need t
This section focuses on:
Actionchains class
Context_click () Right-click
Double_click () Double-click
Drag_and_drop () drag
The test of the product is a right click on the file list will pop up a shortcut menu, you can easily select the shortcut menu to select the file to operate (delete, move, rename), before learning elements of the Click is very simple:
driver.find_element_by_id ("xxx"). Click ()
Then the mouse double-click, right click, drag, etc. is this the way it is written? For ex
, powerful Chrome browser can automatically help you to generate elements of XPath, CSS and other properties. Take Baidu Home Source example, in the page source files, positioning to the element, right-click, the effect is as follows:Generated code after the copy, for this scenario can be directly used, but in view of the current page update is very frequent, it is recommended to simply learn under the selector of XPath, CSS, and other important methods, so we can write very flexible code, the p
a contentTitle_contains Title contains a contentPresence_of_all_elements_located y element is loaded, passed in the locating tuple, as (by.id, ' P ')visibility_of element visible, incoming locator tupleText_to_be_present_in_element an element literal contains a literalText_to_be_present_in_element_value An element value contains a fileElement_to_be_clickable an element can be clickedWait a minute6 Browser forward and backwardBrowser.forward ()Browser.back ()7CookiesCookies can be viewed, added
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.