webdriver

【转】 selenium3+JAVA】界面自动化测试教程(四)——浏览器的打开url、前进、后退、刷新和cookie的操作

Deadly 提交于 2020-02-26 14:50:48
https://blog.csdn.net/df0128/article/details/82823495 1、打开url 这里打开网址有两个方法,如下所示: System.setProperty("webdriver.chrome.driver", "D:\\test\\driver\\chromedriver.exe"); ChromeDriver chrome = new ChromeDriver(); //第一种方法 chrome.navigate().to("https://www.baidu.com/"); //第二张方法 chrome.get("https://www.baidu.com/"); 1 2 3 4 5 6 1 2 3 4 5 6 上面代码中两种方法都可以打开网站,事实上两者并无区别,但是很显然第二张更容易书写。 2、浏览器的前进 代码如下,此方法需要注意的是要确定网页有可以前进的地址,如果做过后退操作可以使用此方法: System.setProperty("webdriver.chrome.driver", "D:\\test\\driver\\chromedriver.exe"); ChromeDriver chrome = new ChromeDriver(); chrome.navigate().forward(); 1 2 3 1 2 3 3

RobotFramework自动化测试框架

折月煮酒 提交于 2020-02-26 14:13:39
https://www.cnblogs.com/laoqing/p/9350214.html Selenium出来已经有很多年了,从最初的Selenium1到后来的Selenium2,也变得越来越成熟,而且也已经被很多公司广泛使用。Selenium发展的过程中,分了很多模块,这里我们主要介绍Webdriver,Webdriver已经被很多浏览器所兼容。WebDriver在自动化脚本和浏览器之间充当的角色和之前介绍的Appium很像。 由于现在很多的浏览器都已经主动支持和兼容了WebDriver,所以Webdriver在启动后,会确认浏览器的native component是否存在可用而且版本匹配,接着就在目标浏览器里启动使用Selenium自己设计定义的协议(WebDriver Wire Protocol),WebDriver Wire协议是通用的,也就是说不管是FirefoxDriver还是ChromeDriver等,启动之后都会在某一个端口启动基于这套协议的Web 服务,WebDriver Wire协议是一套基于RESTful的web服务。 在调用WebDriver的时候,实际上是给在浏览器上启动的RESTful服务监听端口上发送http请求,请求会以WebDriver Wire协议规定的JSON格式的字符串来告诉Selenium希望浏览器执行什么样的操作。

Selenium基本操作

[亡魂溺海] 提交于 2020-02-26 14:12:33
一、定位元素 Selenium有两类八种定位元素的方式。 1. 单个元素定位 基本方式 No. 定位方式 方法 说明 1 ID定位 browser.find_element_by_id("ID名") HTML标签ID属性 2 名字定位 browser.find_element_by_name("名字") HTML表单标签名字属性 3 标签名定位 browser.find_element_by_tag_name("标签名") HTML标签 4 类名定位 browser.find_element_by_class_name("类名") HTML标签class属性 5 CSS选择器定位 browser.find_element_by_css_selector("CSS选择器") CSS选择器 6 XPath定位 browser.find_element_by_xpath("xpath") xpath 7 链接文字 browser.find_element_by_link_text("链接文字") a标签文本完全匹配 8 部分链接文字 browser.find_element_by_link_text("部分链接文字") a标签文本部分匹配 实践 以百度的Logo图片和输入框为例 <img hidefocus="true" class="index-logo-src" src="//www

Python + Selenium + AutoIt 模拟键盘实现另存为、上传、下载操作详解

浪子不回头ぞ 提交于 2020-02-26 02:57:35
前言 在web页面中,可以使用selenium的定位方式来识别元素,从而来实现页面中的自动化,但对于页面中弹出的文件选择框,selenium就实现不了了,所以就需引用AutoIt工具来实现。 AutoIt介绍 AutoIt简单介绍下,AutoIt 目前最新是v3版本,这是一个使用类似BASIC脚本语言的免费软件,它设计用于Windows GUI(图形用户界面)中进行自动化操作。它利用模拟键盘按键,鼠标移动和窗口/控件的组合来实现自动化任务。而这是其它语言不可能做到或无可靠方法实现的(例如VBScript和SendKeys)。 实现原理: 使用AutoIt下的工具去定位页面外的元素属性值,其次再利用AutoIt下的工具编写合适的脚本,然后将脚本编译成可执行文件,最后在自动化实现时,直接调用此脚本实现文件的上传、下载等操作。 备注:定位元素、编写脚本和编译,需要借助AutoIt提供的工具,但是脚本编译成可执行文件后,可以直接使用。 AutoIt的下载与安装就不再赘述,下载地址如下: https://www.autoitscript.com/site/autoit/downloads/ 安装成功后会出现如下菜单: AutoIt工具使用 1.AutoIt Window Info用来识别Windows控件,根据识别的控件信息编写脚本;x86为32位 2.SciTE Script

二次开发的Selenium Demo版本

时光怂恿深爱的人放手 提交于 2020-02-25 21:27:36
1 文件名你们自己命名就好,至于为什么要重写强制位移的函数呢,是因为Mac上Selenium不支持拖拽,只能这样做了,4个文件----------------------------------------------------------------------------------------------def login(auto): 2 """ 3 遍历上方login_config 4 按照其格式进行自动化操作 5 """ 6 for item in login_config: 7 for key, value in item.items(): 8 try: 9 # 把auto与key组合起来并传入value执行 10 # 如auto.refresh(2) 11 getattr(auto, key)(value) 12 except Exception as error: 13 print(error) 14 def Test(auto): 15 """ 16 遍历上方login_config 17 按照其格式进行自动化操作 18 """ 19 for item in Test_config: 20 for key, value in item.items(): 21 try: 22 # 把auto与key组合起来并传入value执行 23 # 如auto

移动端测试 - Appium-Python-Client-API

烈酒焚心 提交于 2020-02-25 19:29:26
About Appium-Python-Client-API 来看看 appium-python-client 库都有哪些常用的api可用。 contexts Lib\site-packages\appium\webdriver\extensions\context.py @property def contexts(self): """Returns the contexts within the current session. 返回当前会话中的上下文,使用后可以识别H5页面的控件 Usage: driver.contexts Return: :obj:`list` of :obj:`str`: The contexts within the current session """ return self.execute(Command.CONTEXTS)['value'] 可以跟 switch_to_content() 连用,用于切换到相应的H5控件中。 current_context Lib\site-packages\appium\webdriver\extensions\context.py @property def context(self): """Returns the current context of the current session.

Why do some elements exist but not interactable/displayed?

血红的双手。 提交于 2020-02-25 08:30:34
问题 I'm pretty new to testing, trying to gain a better understanding of what exactly is going on. I'm finding some of our test codes are failing when the css selector element has a waitUntilCanInteract or waitUntilDisplayed attached to it even though when I do a chrome inspect the element is showing up in the browser. Changing them to a waitUntilExists gets them to a passing point so I was wondering what exactly is going on to create this situation? 回答1: Precisesly Selenium deals with three

“Message=unknown error: cannot focus element” while executing tests through Selenium, ChromeDriver and Chrome

情到浓时终转凉″ 提交于 2020-02-25 04:30:10
问题 I am trying to send key for a drop down list in google chrome browser but i am receiving this error OpenQA.Selenium.WebDriverException HResult=0x80131500 Message=unknown error: cannot focus element (Session info: chrome=68.0.3440.106) (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64) Source=WebDriver StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium

“Message=unknown error: cannot focus element” while executing tests through Selenium, ChromeDriver and Chrome

陌路散爱 提交于 2020-02-25 04:30:05
问题 I am trying to send key for a drop down list in google chrome browser but i am receiving this error OpenQA.Selenium.WebDriverException HResult=0x80131500 Message=unknown error: cannot focus element (Session info: chrome=68.0.3440.106) (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64) Source=WebDriver StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium