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的更多相关文章

  1. Java +selenium Navigation接口介绍

    Navigation接口主要实现对浏览器的前进.后退.打开网址.刷新当前页面等操作的. void back():就是操作当前页面后退,相当于网页的后退按钮. void forward():就是操作当前 ...

  2. selenium 打开浏览器

    import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebE ...

  3. selenium webdriver 右键另存为下载文件(结合robot and autoIt)

    首先感谢Lakshay Sharma 大神的指导 最近一直在研究selenium webdriver右键菜单,发现selenium webdriver 无法操作浏览器右键菜单,如图 如果我想右键另存为 ...

  4. selenium 下载百度音乐并验证

    package baidu; import java.io.File; import java.io.IOException; import java.util.List; import org.ap ...

  5. selenium web driver 实现截图功能

    在验证某些关键步骤时,需要截个图来记录一下当时的情况 Webdriver截图时,需要引入 import java.io.File; import java.io.IOException; import ...

  6. (原创)如何使用selenium 驱动chrome浏览器并且打开方式为手机模式-转载请注明出处

    随着移动设备使用率的不断增加,移动页面的测试也变得越来越重要. 对于互联网公司M站的测试,如果不通过专用的appium等移动端测试工具是否还有方便快捷的办法呢?答案当然是有啊. 使用chrome dr ...

  7. selenium web driver 配合使用testng

    首先为eclipse添加testng插件 步骤如下:help->Install New SoftWare... 2. 添加testng链接,该链接可以在这里找到 For the Eclipse ...

  8. selenium webdriver学习(一)

    package baidu; import java.io.File; import java.io.IOException; import junit.framework.TestCase; imp ...

  9. Page Object Model (Selenium, Python)

    时间 2015-06-15 00:11:56  Qxf2 blog 原文  http://qxf2.com/blog/page-object-model-selenium-python/ 主题 Sel ...

随机推荐

  1. spring中基于注解使用AOP

    本文内容:spring中如何使用注解实现面向切面编程,以及如何使用自定义注解. 一个场景 比如用户登录,每个请求发起之前都会判断用户是否登录,如果每个请求都去判断一次,那就重复地做了很多事情,只要是有 ...

  2. left join inner join 区别

    left 以左表为准,左表在右表没有对应的记录,也为显示(右表字段填空). inner 需要满足两张表都有记录. 不管哪种join 一对多最终的结局 只会是多条记录

  3. hadoop 集群 master datanode 没有启动

    2018-02-07 02:47:50,377 WARN org.apache.hadoop.hdfs.server.common.Storage: java.io.IOException: Inco ...

  4. Java的selenium代码随笔(2)

    import java.awt.AWTException;import java.awt.Robot;import java.awt.Toolkit;import java.awt.datatrans ...

  5. mysql自动断开该连接解决方案

    mysql连接的空闲时间超过8小时后 MySQL自动断开该连接解决方案 作者: MySQL 的默认设置下,当一个连接的空闲时间超过8小时后,MySQL 就会断开该连接,而 c3p0 连接池则以为该被断 ...

  6. DAY17、常用模块

    一.time模块 1.时间戳(timestamp):time.time()     #可以作为数据的唯一标识   是相对于1970-1-1-0:0:0时间插值 2.延迟线程的运行:time.sleep ...

  7. Python——Socket编程

    一.TCP 1.客户端 import socket sk = socket.socket() # 买个手机 sk.connect(('127.0.0.1',8080)) # 拨号 ret = sk.r ...

  8. Ubuntu下基于Virtualenv构建Python开发环境

    1.安装virtualenv并建立虚拟环境 1).更新pip版本 sudo pip install --upgrade pip 如果出现如下异常: File , in <module> f ...

  9. 第六十九天 dom与bom

    1.节点 dom与bom属 // DOM:文档对象模型 =>提高给用户操作document obj的标准接口 // DOM:以document为根,树状展开所有子节点 节点分类 // 节点分类: ...

  10. JS获取字符串实际长度(包含汉字)的简单方法

    方法一: var jmz = {}; jmz.GetLength = function(str) { ///<summary>获得字符串实际长度,中文2,英文1</summary&g ...