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 ...
随机推荐
- 如何用php实现分页效果
分页效果在网页中是常见的,可是怎样才能实现分页呢,今天做了两种方法来实现一下分页的效果 首先,我们需要准备在数据库里面准备一个表,并且插入数据,这些都是必需的前提工作了,不多说,如图所示(库名为jer ...
- warn_alloc():page allocation failure问题分析
关键词:warn_alloc().__GFP_XXX.order.CMA等等. 在内存申请的时候经常会遇到类似“ xxx: page allocation failure: order:10...”类 ...
- Python第二天: 变量详解及变量赋值
目录 什么是变量? 怎么写一个好的变量? 下划线命名法及驼峰命名法 结语 目录 此文章针对刚学Python的小白,若觉得对变量有很好的掌握,可以观看其他的文章 在这里, 我说一下我对变量的简单总结: ...
- Auto Layout - BNR
继续UIImageView - BNR篇. 通过Homepwner TARGETS -> General -> Deployment Info -> Devices中的iPhone改 ...
- Python 输出文件内容到网络端口
Python 输出文件内容到网络端口 $ cat mySocketTest.py import sys import time import socket if __name__ == "_ ...
- Linux使用百度云
导读 百度云没有Linux客户端,于是有大神用Go语言写出来一个叫BaiduPCS-Go的命令行盘客户端,可以通过终端操作百度云盘,在Linux上实现上传下载.但是因为是命令行版本的,对没有命令行使用 ...
- WEB通知和React Native之即时通讯(iOS Android)
WEB通知和React Native之即时通讯(iOS Android) 一,需求分析 1.1,允许服务器主动发送信息给客户端,客户端能监听到并且能接收. 1.2,为了方便同一个系统内的用户可以指定某 ...
- Ajax跨域请求,无法传递及接收cookie信息
最近在做一个系统遇到一个问题,在网上找个一个和我遇到相同问题的(原文地址:https://www.cnblogs.com/helloyy/p/6109665.html)按照他的步骤还是没有解决,继续查 ...
- vue組件傳值及vuex的使用
https://blog.csdn.net/u011175079/article/details/79161029 https://blog.csdn.net/sisi_chen/article/de ...
- 8.docker的安全性
在查看Docker安全性时,有四个主要方面需要考虑: 内核的内在安全性及其对命名空间和cgroup的支持; Docker守护进程本身的攻击面; 容器配置配置文件中的漏洞,默认情况下或用户自定义时. 内 ...