Now many web content is dynamically generated, dynamic page information extraction can use selenium. To extract dynamic page information.
One way is to start the browser to execute the JS code, then the first step is to start the browser first.
The following code:
Import Org.openqa.selenium.WebDriver;
Import Org.openqa.selenium.chrome.ChromeDriver;
public class
Java Selenium building xxx face Browser1.http://phantomjs.org/Download Windows version Phantomjs2. exe file will be found in the bin directory after decompression3. Test the code:Copy CodePackage SE;Import Org.openqa.selenium.WebDriver;Import Org.openqa.selenium.firefox.FirefoxDriver;Import Org.openqa.selenium.phantomjs.PhantomJSDriver;public class Test {public static void main(String[] args) { // TODO Auto-generated method stub// System.setProp
:8888/xxx/Admin_user=adminadmin_pswd=123456Admin_name= Administratorqa_user=test01qa_pswd=123456Qa_name= Test 1rd_user=test02rd_pswd=123456Rd_name= Test 2[Test]Dir_screenshot=d:/test_browser/data/screenshotImport Configparserconfig=configparser.configparser () config.read (' base.conf ') print config.get (' info ', ' qa_user ')Four. Multi-browserUse class inheritance to generate classes for different browsers for multi-browser supportFrom new import C
First, the scene: in the non-logoff system switch different account login system, login will have browser cache, resulting in unusually slow logon time. is related to developing the browser cache processing mechanism.Second, the solution:Gets the browser cookie, adding code to clear the cache before the login method. Import Org.openqa.selenium.Cookie; // Get
The Selenium control browser needs to download the corresponding version of the driver and unzip the downloaded driver and then copy it to the Python installation directory.1. ChromeDrive the corresponding version and; https://npm.taobao.org/mirrors/chromedriver/2. FirefoxDrive; https://github.com/mozilla/geckodriver/releases/3. IEDrive; http://www.cr173.com/soft/195732.htmlenable protected mode for IEOpen
I because is engaged in automation time is not long, so tread a lot of pits. Be prepared to record these pits.The most basic of automated testing is to open the browser and then maximize the Windows window, if the window is not maximized, the invisible place cannot be automated.At first Baidu has a lot of window maximization method, the most commonly used is:Webdriver driver=new chromedriver ();Driver.manage (). window (). Maximize ();But I found out
ObjectiveSELENIUM+PHANTOMJS can open the browser without interface, implement the silent mode to start the browser to complete the automated test, this mode is excellent, do not need to occupy the computer screen.However, phantomjs this hole is still more, and encountered problems can not see the page, unable to troubleshoot problems.In fact, the Chrome browser c
This afternoon to learn a bit of writing automation scripts, problems encountered, record.Workaround: Download the Geckodriver.exe and put the downloaded geckodriver.exe into the D:\MyConfiguration\wtt42800\AppData\Local\Programs\Python\ Python36-32 (python's installation directory)Reference Link: http://jingyan.baidu.com/article/c910274b87b84acd361d2da3.htmlhttps://github.com/mozilla/geckodriver/releases/tag/v0.19.0https://pypi.python.org/pypi/selenium
directory where he is located to the PATH environment variable.5, if the Internet Explorer settings security is high, do not select "Enable Protected mode" in the "Internet options" (Protected mode), or you may encounter error prompts.
Pros: Visually simulate the user's actual operation and provide complete support for JavaScript.Cons: It is the slowest in all browsers and can only be run under Windows, and the support for CSS and XPath is not good enough.Error during Operation Message:inv
Purpose of Study:
Mastering the advanced applications of WebdriverFormal steps:
#-*-coding:utf-8-*- fromSeleniumImportWebdriver fromSelenium.webdriverImportActionchains fromSelenium.webdriver.support.uiImportSelect fromSelenium.webdriver.common.keysImportKeys fromSelenium.common.exceptionsImportwebdriverexceptionImportUnitTestImportOSImport TimeImportTracebackclassWebdriverapi (unittest. TestCase):defsetUp (self):#each use case executes and executes before a single use case is run
Code:# Coding=utf-8 from Import webdriverdriver=webdriver. Chrome () # calls Chrome browser driver.get ('https://www.baidu.com ')print driver.titledriver.quit ()------------------------------------------------------------------------------If you call another browser, the code is replaced:Driver=webdriver. Ie () #调用ie浏览器 driver=webdriver. Firefox () #调用firefox浏览器1 run the script under Chrome, you need
In Windows cmd execute "python test.py", no problem, the browser open normally, the test results are normal.Problem:But if it is in Jenkins, choose "Execute Windows Batch command", configure "Python test.py" run test, this time there will be a problem, Chrome browser will not open, but there are processes in the background, Test.py runs in the background, but runs test.py in the background and the
actually go directly to the script. However, sometimes it is possible to set the agent and port as needed. Although my own script does not need to be set, it uses the default proxy and port. But before the script made a mistake, I mistakenly think it is a proxy setup has a problem, so also write script to proxy reset the next, later still did not pass, colleagues help me after analysis said no, Magic commented out code incredibly passed, really do not know where the error before, OK, it is lear
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.