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. C#7.0中的解构功能---Deconstruct

    解构元组 C#7.0新增了诸多功能,其中有一项是新元组(ValueTuple),它允许我们可以返回多个值,并且配合解构能更加方便的进行工作,如下面例子 static void Main(string[ ...

  2. DependencyInjection源码解读之ServiceProvider

    var services = new ServiceCollection(); var _serviceProvider = services.BuildServiceProvider(); serv ...

  3. 树的平衡之AVL树——错过文末你会后悔,信我

    学习数据结构应该是一个循序渐进的过程: 当我们学习数组时,我们要体会数组的优点:仅仅通过下标就可以访问我们要找的元素(便于查找). 此时,我们思考:假如我要在第一个元素前插入一个新元素?采用数组需要挪 ...

  4. appium框架之bootstrap

    (闲来无事,做做测试..)最近弄了弄appium,感觉挺有意思,就深入研究了下. 看小弟这篇文章之前,先了解一下appium的架构,对你理解有好处,推荐下面这篇文章:testerhome appium ...

  5. SQL拼接字符串时单引号转义问题 单引号转义字符

    要拼接一个单引号到已有字符串前后, 开始以为(错误)可以用  \ 转义,如下: '\''+ str+'\'' 看颜色就知道是不行的. 正确方法是两个单引号就转义为单引号,如下: ''''+str+'' ...

  6. win10启动nginx但是访问不了

    首先验证配置,是否正常:nginx -t 我这里配置正常. 我的原因是设置了代理,打开IE浏览器,设置>Internet选项>连接>局域网设置>代理删除.

  7. redis一主二从加哨兵

    redis版本:redis-3.0.6.tar.gz master:192.168.3.180 slave:192.168.3.184 (机器原因,两从都在这上面) 一.redis安装 cd /roo ...

  8. 语义SLAM研究现状总结

    博客转载自:https://blog.csdn.net/xiaoxiaowenqiang/article/details/81051010 原文标题:深度学习结合SLAM 语义slam 语义分割 端到 ...

  9. 使用nginx部署网站

    前面的话 如果服务器只需要放置一个网站程序,解析网站到服务器的网站,网站程序监听80端口就可以了.如果服务器有很多应用,借助nginx不仅可以实现端口的代理,还可以实现负载均衡.本文将详细介绍前端及n ...

  10. [模板] 二分图博弈 && BZOJ2463:[中山市选2009]谁能赢呢?

    二分图博弈 from BZOJ 1443 游戏(二分图博弈) - free-loop - 博客园 定义 1.博弈者人数为两人,双方轮流进行决策. 2.博弈状态(对应点)可分为两类(状态空间可分为两个集 ...