webdriver

selenium的原理及其发展史

淺唱寂寞╮ 提交于 2020-03-30 04:51:02
Selenium1 介绍 ThoughtWorks的测试人员为了减少手工测试,实现了一套基于javaScript语言的代码库,可分为Selenium IDE 、Selenium RC和Selenium Grid 其中 Selenium IDE是Firefox的插件,负责录制和回放脚本, Selenium Grid在不同的环境以并发的方式执行脚本,来缩短测试时间。 Selenium RC支持多浏览器、不同的汇编语言, 由于自身的是实现机制, selenium无法突破浏览器的沙盒限制(JavaScript的安全机制——同源策略,外部引用的JavaScript文件URL和当前网页的域名不一致,浏览器会拒绝只想此JavaScript文件中的代码),以至于很多场景无法实现。 Selenium2的介绍 Selenium1+webdriver Webdriver 直接让测试工具调用浏览器和操作系统的本身提供的内置方法。更好的模拟真实环境。而且绕过JavaScript的沙盒限制,所以将这2个项目进行了合并。 Webdriver的原理。 由于客户端脚本 (java, python, ruby)不能直接与浏览器通信,这时候可以把WebService(实际上就是浏览器厂商提供的driver, 比如IEDriver, ChromeDriver,它们都实现了WebDriver's wire protocol

第一个web自动化测试脚本

人盡茶涼 提交于 2020-03-29 11:37:30
1,之前因为进行APP自动化,因为Eclipse已经配置过了Maven 2,创建Maven项目 3.引入selenium 框架 查看maven仓库:http://mvnrepository.com/ 搜素selenium java 复制到eclipse的pom。xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>come.test</groupId> <artifactId>WebAuto</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org

使用selenium webdriver+beautifulsoup+跳转frame,实现模拟点击网页下一页按钮,抓取网页数据

你说的曾经没有我的故事 提交于 2020-03-29 04:05:55
  记录一次快速实现的python爬虫,想要抓取中财网数据引擎的新三板板块下面所有股票的公司档案,网址为http://data.cfi.cn/data_ndkA0A1934A1935A1986A1995.html。   比较简单的网站不同的页码的链接也不同,可以通过观察链接的变化找出规律,然后生成全部页码对应的链接再分别抓取,但是这个网站在换页的时候链接是没有变化的,因此打算去观察一下点击第二页时的请求   发现使用的是get的请求方法,并且请求里有curpage这个参数,貌似控制着不同页数,于是改动了请求链接中的这个参数值为其他数值发现并没有变化,于是决定换一种方法,就是我们标题中提到的使用selenium+beautifulsoup实现模拟点击网页中的下一页按钮来实现翻页,并分别抓取网页里的内容。   首先我们先做一下准备工作,安装一下需要的包,打开命令行,直接pip install selenium和pip install beautifulsoup4   然后就是下载安装chromedriver的驱动,网址如下https://sites.google.com/a/chromium.org/chromedriver/downloads,记得配置下环境变量或者直接安装在工作目录下。(还可以使用IE、phantomJS等)   这里我们先抓取每一个股票对应的主页链接,代码如下

Python:使用selenium模块

 ̄綄美尐妖づ 提交于 2020-03-27 09:33:29
一、什么是Selenium selenium 是一套完整的web应用程序测试系统,包含了测试的录制(selenium IDE),编写及运行(Selenium Remote Control)和测试的并行处理(Selenium Grid)。Selenium的核心Selenium Core基于JsUnit,完全由JavaScript编写,因此可以用于任何支持JavaScript的浏览器上。 selenium可以模拟真实浏览器,自动化测试工具,支持多种浏览器,爬虫中主要用来解决JavaScript渲染问题。 二、selenium基本使用 用python写爬虫的时候,主要用的是selenium的Webdriver,我们可以通过下面的方式先看看Selenium.Webdriver支持哪些浏览器 from selenium import webdrive help(webdriver) 执行结果如下,从结果中我们也可以看出基本山支持了常见的所有浏览器: NAME: selenium.webdriver PACKAGE CONTENTS: android (package) blackberry (package) chrome (package) common (package) edge (package) firefox (package) ie (package) opera

[Selenium+Java] How to Upload & Download a File using Selenium Webdriver

谁都会走 提交于 2020-03-27 05:41:35
Original source: https://www.guru99.com/upload-download-file-selenium-webdriver.html Uploading Files For this section, we will use http://demo.guru99.com/test/upload/ as our test application. This site easily allows any visitor to upload files without requiring them to sign up. Uploading files in WebDriver is done by simply using the sendKeys() method on the file-select input field to enter the path to the file to be uploaded. Let's say we wish to upload the file "C:\newhtml.html". Our WebDriver code should be like the one shown below. package newproject; import org.openqa.selenium.*; import

Unable to install Selenium WebDriver through command prompt

三世轮回 提交于 2020-03-26 04:27:26
问题 When I try to install Selenium WebDriver on cmd prompt using command "python setup.py install" I am getting error "The program can't start because api-ms-win-crt-runtime-Il-1-0.dll missing from your computer". I am using Python version-3.7 and I have set the path of the Python in environment variable. Please help me how to solve this issue, I am new to Python. 回答1: Download get-pip.py to a directory in your computer. Then run python get-pip.py Then do pip install -U selenium Then use this in

Is it a way to get the test method name within TestNG listeners on Configuration phase?

旧城冷巷雨未停 提交于 2020-03-25 19:19:28
问题 I have a TestNG listener that implements IInvokedMethodListener. On @BeforeMethod I need to setup some test context, here is the example: public class ThucydidesInvokedMethodListener implements IInvokedMethodListener2 { public void beforeInvocation(final IInvokedMethod method, final ITestResult testResult) { boolean areBeforeMethods = method.getTestMethod().getTestClass().getBeforeTestMethods().length > 0; if ((areBeforeMethods && method.getTestMethod().getTestClass().getBeforeTestMethods()[0

Is it a way to get the test method name within TestNG listeners on Configuration phase?

99封情书 提交于 2020-03-25 19:18:14
问题 I have a TestNG listener that implements IInvokedMethodListener. On @BeforeMethod I need to setup some test context, here is the example: public class ThucydidesInvokedMethodListener implements IInvokedMethodListener2 { public void beforeInvocation(final IInvokedMethod method, final ITestResult testResult) { boolean areBeforeMethods = method.getTestMethod().getTestClass().getBeforeTestMethods().length > 0; if ((areBeforeMethods && method.getTestMethod().getTestClass().getBeforeTestMethods()[0

Python Selenium webdriver: element not interactable: Element is not currently visible and may not be manipulated [duplicate]

别说谁变了你拦得住时间么 提交于 2020-03-25 18:19:43
问题 This question already has answers here : selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable when clicking on an element using Selenium Python (4 answers) ElementNotInteractableException: Message: element not interactable error while sending text to Email field on Quora using Selenium with Python (5 answers) Closed 17 hours ago . I have written following code to interact with the Acxiom website: from selenium import webdriver from webdriver_manager

Selenium-Switch与SelectApi接口详解

给你一囗甜甜゛ 提交于 2020-03-25 08:41:01
Switch 我们在UI自动化测试时,总会出现新建一个tab页面、弹出一个浏览器级别的弹框或者是出现一个iframe标签,这时我们用WebDriver提供的Api接口就无法处理这些情况了。需要用到Selenium单独提供的模块switch_to模块 引用路径 # 第一种方式可以通过直接导入SwitchTo模块来进行操作 from selenium.webdriver.remote.switch_to import SwitchTo # 第二种方式是直接通过Webdriver的switch_to来操作 driver.switch_to 其实webdriver在以前的版本中已经为我们封装好了切换Windows、Alert、Iframe,现在依然可以使用,但是会被打上横线,代表他已经过时了,建议使用SwitchTo类来进行操作。 SwitchToWindows handles = driver.window_handles # SwitchToWindows接受浏览器TAB的句柄 driver.switch_to.window(handles[1]) SwitchToFrame # SwitchToFrame支持id、name、frame的element # 接受定位到的iframe的Element,这样就可以通过任意一种定位方式进行定位了 frameElement = driver