Selenium Navigation
Navigating
Navigate a link with WebDriver:
driver.get("http://www.google.com")
1.Interacting with the page
Element define:
<input type="text" name="passwd" id="passwd-id" />
Find:
element = driver.find_element_by_id("passwd-id")
element = driver.find_element_by_name("passwd")
element = driver.find_element_by_xpath("//input[@id='passwd-id']")
element.send_keys("some text")
element.send_keys(" and some", Keys.ARROW_DOWN)
element.clear()
2.Filling in forms
**SELECT tags:**
element = driver.find_element_by_xpath("//select[@name='name']") //find the first “SELECT” element on the page
all_options = element.find_elements_by_tag_name("option")
for option in all_options:
print("Value is: %s" % option.get_attribute("value"))
option.click() //cycle through each of its OPTIONs in turn, printing out their values, and selecting each in turn
**“Select” class: **
from selenium.webdriver.support.ui import Select
select = Select(driver.find_element_by_name('name'))
select.select_by_index(index)
select.select_by_visible_text("text")
select.select_by_value(value)
select = Select(driver.find_element_by_id('id'))
select.deselect_all()
select = Select(driver.find_element_by_xpath("//select[@name='name']"))
all_selected_options = select.all_selected_options
options = select.options //To get all available options:
# Assume the button has the ID "submit" :)
driver.find_element_by_id("submit").click()
element.submit()
3.Drag and drop
element = driver.find_element_by_name("source")
target = driver.find_element_by_name("target")
from selenium.webdriver import ActionChains
action_chains = ActionChains(driver)
action_chains.drag_and_drop(element, target).perform()
4.Moving between windows and frames
“switch_to_window” method:
driver.switch_to_window("windowName")
How to know the window’s name? Page Source:
<a href="somewhere.html" target="windowName">Click here to open a new window</a>
for handle in driver.window_handles:
driver.switch_to_window(handle)
driver.switch_to_frame("frameName") //swing from frame to frame (or into iframes)
driver.switch_to_frame("frameName.0.child") //access subframes by separating the path with a dot, and you can specify the frame by its index
driver.switch_to_default_content() //come back to the parent frame
5.Popup dialogs
Access the alert with the following:
alert = driver.switch_to_alert() //Return the currently open alert object
6.Navigation: history and location
driver.get("http://www.example.com")
driver.forward() //move backward
driver.back() //move forward
7.Cookies
# Go to the correct domain
driver.get("http://www.example.com")
# Now set the cookie. This one's valid for the entire domain
cookie = {‘name’ : ‘foo’, ‘value’ : ‘bar’}
driver.add_cookie(cookie)
# And now output all the available cookies for the current URL
driver.get_cookies()
Selenium Navigation的更多相关文章
- Java +selenium Navigation接口介绍
Navigation接口主要实现对浏览器的前进.后退.打开网址.刷新当前页面等操作的. void back():就是操作当前页面后退,相当于网页的后退按钮. void forward():就是操作当前 ...
- selenium 打开浏览器
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebE ...
- selenium webdriver 右键另存为下载文件(结合robot and autoIt)
首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...
- selenium 下载百度音乐并验证
package baidu; import java.io.File; import java.io.IOException; import java.util.List; import org.ap ...
- selenium web driver 实现截图功能
在验证某些关键步骤时,需要截个图来记录一下当时的情况 Webdriver截图时,需要引入 import java.io.File; import java.io.IOException; import ...
- (原创)如何使用selenium 驱动chrome浏览器并且打开方式为手机模式-转载请注明出处
随着移动设备使用率的不断增加,移动页面的测试也变得越来越重要. 对于互联网公司M站的测试,如果不通过专用的appium等移动端测试工具是否还有方便快捷的办法呢?答案当然是有啊. 使用chrome dr ...
- selenium web driver 配合使用testng
首先为eclipse添加testng插件 步骤如下:help->Install New SoftWare... 2. 添加testng链接,该链接可以在这里找到 For the Eclipse ...
- selenium webdriver学习(一)
package baidu; import java.io.File; import java.io.IOException; import junit.framework.TestCase; imp ...
- Page Object Model (Selenium, Python)
时间 2015-06-15 00:11:56 Qxf2 blog 原文 http://qxf2.com/blog/page-object-model-selenium-python/ 主题 Sel ...
随机推荐
- webservice调用和生成
webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...
- 偶现bug如何处理?
请先允许我对此类bug进行吐槽,相信做测试的同学都碰见过这种bug! 我们在测试过程中经常会碰见一类很头疼的bug,就是偶现性的bug,所谓偶现性,是相对于必现而言,这类bug有些可以有重现路径,但是 ...
- iOS开发基础-KVC简单介绍
一.KVC介绍 键值编码(Key Value Coding,KVC):使开发者不必进行任何操作就可以进行属性的动态读写. KVC操作方法由 NSKeyValueCoding 协议提供,而 NSObje ...
- C# 递归构造树状数据结构(泛型),如何构造?如何查询?
十年河东,十年河西,莫欺少年穷. 学无止境,精益求精 难得有清闲的一上午,索性写篇博客. 首先,我们需要准备一张表,如下范例: create table TreeTable ( TreeId ) no ...
- 基于 HTML5 结合互联网+ 的 3D 隧道
前言 目前,物资采购和人力成本是隧道业发展的两大瓶颈.比如依靠民间借贷,融资成本很高:采购价格不透明,没有增值税发票:还有项目管控和供应链管理的问题.成本在不断上升,利润在不断下降,隧道产业的“互联网 ...
- idea 配置 jdk tomcat
https://blog.csdn.net/cxjsnail/article/details/80018519 1. 安装IntelliJ IDEA IDEA 对maven有完美的支持,有强大的语法 ...
- 在线解析JSON+ AsyncTaskLoader
效果图: 获取并解析Json package com.example.admin.quakereport; import android.text.TextUtils;import android.u ...
- JarvisOJ Misc shell流量分析
分析一下shell流量,得到flag 看着一大推的数据记录头都大了,并没有什么wireshark的使用经验,开始胡搞 首先用notepad++打开,搜索flag字样找到了一个类似于python脚本的东 ...
- Centos6 iptables 防火墙设置【转】
1.指令 vi /etc/sysconfig/iptables 添加以下内容和要开放的端口 # Firewall configuration written by system-config-fire ...
- Nginx-Tomcat搭建负载均衡(转载)
一. 工具 nginx-1.8.0 apache-tomcat-6.0.33 二. 目标 实现高性能负载均衡的Tomcat集群: 三. 步骤 1.首先下载Nginx,要下载稳定版: 2 ...