webdriver

Selenium2(WebDriver)_如何判断WebElement元素对象是否存在

这一生的挚爱 提交于 2020-01-25 22:32:50
1.  selenium中如果去寻找元素,而元素不存在的话,通常会抛出NoSuchElementException 导致测试失败,但有时候,我们需要去确保页面元素不存在,才是我们正确的验收条件下面的方法可以用来判定页面元素是否存在 1 public boolean doesWebElementExist(WebDriver driver, By selector) 2 { 3 4 try 5 { 6 driver.findElement(selector); 7 return true; 8 } 9 catch (NoSuchElementException e) 10 { 11 return false; 12 } 13 } 2. 一般有这样的应用场合,例如我们要验证在一个网站是否登录成功,那么可以通过判断登录之后是否显示相应元素: WebElement linkUsername = driver.findElement(By.xpath("//a[contains(text(),"+username+")]")); return linkUsername.isDisplayed(); 这一方法的前提是:该元素之前已经存在,仅仅需要判断是否被显示。 现在存在另一种场合,页面元素并不存在,即通过driver

Selenium2+python自动化46-js解决click失效问题

蓝咒 提交于 2020-01-25 11:24:37
前言 有时候元素明明已经找到了,运行也没报错,点击后页面没任何反应。这种问题遇到了,是比较头疼的,因为没任何报错,只是click事件失效了。 本篇用2种方法解决这种诡异的点击事件失效问题 一、遇到的问题 1.在练习百度的搜索设置按钮时,点保存设置按钮,alert弹出没弹出(代码没报错,只是获取alert失败),相信不只是我一个人遇到过。 二、点击父元素 1.遇到这种问题,应该是前面操作select后导致的后遗症(因为我注释掉select那段是可以点击成功的) 2.第一种解决办法,先点击它的父元素一次,然后再点击这个元素 3.实现代码如下 三、js直接点击 1.遇到这种诡异问题,是时候出绝招了:js大法 2.用js直接执行点击事件 四、参考代码 # coding:utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.select import Select import time driver = webdriver.Firefox() url = "https://www.baidu.com" driver.get(url) time.sleep(3) mouse =

Appium+python自动化(二十九)- 模拟手指在手机上多线多点作战 - 多点触控(超详解)

回眸只為那壹抹淺笑 提交于 2020-01-25 11:18:59
简介 在网页中我们经常使用缩放操作来便利的查看具体的信息,在appium中使用MultiAction多点触控的类来实现。MultiAction是多点触控的类,可以模拟用户多点操作。主要包含加载add()和执行perform()两个方法. 问题思考 在使用地图 App中,我们经常需要对界面进行缩放操作来更加便利的查看位置。那么在Appium中怎样去模拟这类操作呢? MultiAction MultiAction 是多点触控的类,可以模拟用户多点操作。主要包含 add() 和 perform() 两个方法, MultiAction可以结合前面所学的 ActionTouch 可以模拟出用户的多个手指滑动的操作效果; MultiAction一般和TouchAction结合使用,故需要导入以下模块: from appium.webdriver.common.multi_action import MultiAction from appium.webdriver.common.touch_action import TouchAction 加载: 方法 add(self, *touch_actions)将TouchAction对象添加到MultiAction中,稍后再执行。 参数: touch_actions - 一个或多个TouchAction对象,描述一个手指要执行的动作链 用法 a1

Switching back to parent frame after it's no longer in DOM in Selenium

♀尐吖头ヾ 提交于 2020-01-25 04:36:06
问题 I have the following page <body> <iframe id="outer_frame"> <iframe id="search_button_frame"> <button id="search_button"></button> </iframe> </iframe> </body> Now after I click on the search_button the two frames outer_frame and search_button_frame are no longer in DOM and instead the page becomes like this <body> <iframe id="form_frame"> ... </iframe> </body> I'm trying to go to the search_button then get out of the frames into the main page, and then switching to the form_frame using this:

APP自动化测试的环境配置

丶灬走出姿态 提交于 2020-01-25 02:53:18
什么是Appium? 第三方自动化框架(工具),扩充了selenium webdriver 协议,在原有的基础上添加了移动端测试API selenium webdriver 指定了客户端到服务端的协议 appium 是一个开源的、跨平台的自动化测试工具,用于app的自动化测试 appium 是跨平台的,支持android,ios,firefoxos等操作系统下的app测试 什么是selenium? 用于web应用程序测试工具,直接运行在浏览器,模拟用户操作,覆盖Windows、Linux、Mac,覆盖 IE、Chrome、firefox等浏览器,Java、Python多种语言进行脚本编写 官网: https://docs.seleniumhq.org/download/ 版本: http://selenium-release.storage.googleapis.com/index.html 什么情况适合做自动化: 周期比较长的、需求比较稳定的、迭代周期比较长的 使用appium 做APP自动化测试的原理: 1)appium 的核心其实是一个暴露了一系列rest api的server 2)这个server的功能其实很简单:监听一个端口(4723),然后接受由client发送的command 3)然后翻译 这些command,把这些command

What does contains(., 'some text') refers to within xpath used in Selenium

梦想与她 提交于 2020-01-25 02:47:47
问题 I am new to selenium coding, and I am seeing several xpaths that contain (.,'followed by something') what does the ., refer to? 回答1: The . character within the xpath is the short form of text() As an example if an WebElement is represented within the DOM Tree as: <span>Use this payment method</span> Effective Locator Strategies will be: xpath 1 : //span[text()='Use this payment method'] xpath 2 : //span[contains(., 'Use this payment method')] Reference You can find a couple of relevant

Selenium之自动发送163邮件.py

孤街醉人 提交于 2020-01-25 00:43:07
版一: import timeimport datetimefrom selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWait # 等待页面加载某些元素from selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Byfrom getpass import getpassdef login(user, pwd): """ 登录163邮箱 """ # 由于可以扫码登录,而我们选择用户名和密码登录,所以,要点击 密码登录 time.sleep(1) wait.until(EC.presence_of_element_located((By.ID, 'switchAccountLogin'))).click() # 进入iframe,因为有多个iframe,所以获取的是数组,在分析页面后,数组0索引的iframe是登陆的iframe time.sleep(3) iframe = driver.find_elements_by_tag_name('iframe') # print(iframe) ''' [ <selenium

Exception in thread “main” java.lang.NoClassDefFoundError: okhttp3/ConnectionPool with Selenium and Java

被刻印的时光 ゝ 提交于 2020-01-24 23:40:11
问题 i have a simple Selenium Test Code: public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/home/chromedriver"); WebDriver driver= new ChromeDriver(); driver.get("http://google.com"); } And i get this Error: Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/ConnectionPool | Caused by: java.lang.ClassNotFoundException: okhttp3.ConnectionPool I think the jars and Dependency are ok but i still get this Error 回答1: please check of this jars files

FirePath not displaying HTML code after typing x-path

99封情书 提交于 2020-01-24 23:19:13
问题 Upon typing xpath in fire-path text field, if x-path is correct then it'll display the corresponding HTML code. It was working fine previously. But now it's not displaying the corresponding HTML code even though the xpath is correct. Can anyone help me to find the solution for this problem? I even uninstalled fire-path and installed again but still, it's not working. 回答1: If you visit the GitHub Page of FirePath, it clearly mentions that : FirePath is a Firebug extension that adds a

Multiple iframe tags Selenium webdriver

微笑、不失礼 提交于 2020-01-24 22:21:28
问题 I am trying to use selenium to send credit card info onto a site, and each element is contained in a separate iframe tag in the HTML. For example, the box to enter a credit card number is contained in the first iframe tag, and the card holder name is contained in the second iframe, and so on, and so forth. I am able to access the first iframe tag, and send the credit card number into the box, however I an unable to locate the cardholder name iframe tag, and thus cannot send the keys to enter