webdriver函数

import sys; print(‘%s %s‘ % (sys.executable or sys.platform, sys.version))
PyDev console: starting.
C:\Python27\python.exe 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]

import subprocess
import time

import scrapy

from selenium import webdriver
from scrapy.spiders.crawl import CrawlSpider
loginUri = r‘http://www.test1.com/‘
driver = webdriver.Firefox()

driver.get(loginUri)
driver.find_element_by_name(‘input1‘).send_keys(‘mycnblogs_2015‘)
driver.find_element_by_name(‘input2‘).send_keys(‘075528560160...cnblogs‘)

driver.find_element_by_name(‘signin‘).click()
alllinks = driver.find_elements_by_xpath(r‘//a‘)
a = alllinks[0]
pr
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name ‘pr‘ is not defined
print a
<selenium.webdriver.remote.webelement.WebElement (session="f57849aa-5174-4dea-93c1-030e4fbf21f8", element="{14bf9be1-05c9-440f-adc8-2be8ac5696aa}")>
dir(a)
[‘__class__‘, ‘__delattr__‘, ‘__dict__‘, ‘__doc__‘, ‘__eq__‘, ‘__format__‘, ‘__getattribute__‘, ‘__hash__‘, ‘__init__‘, ‘__module__‘, ‘__ne__‘, ‘__new__‘, ‘__reduce__‘, ‘__reduce_ex__‘, ‘__repr__‘, ‘__setattr__‘, ‘__sizeof__‘, ‘__str__‘, ‘__subclasshook__‘, ‘__weakref__‘, ‘_execute‘, ‘_id‘, ‘_parent‘, ‘_upload‘, ‘_w3c‘, ‘clear‘, ‘click‘, ‘find_element‘, ‘find_element_by_class_name‘, ‘find_element_by_css_selector‘, ‘find_element_by_id‘, ‘find_element_by_link_text‘, ‘find_element_by_name‘, ‘find_element_by_partial_link_text‘, ‘find_element_by_tag_name‘, ‘find_element_by_xpath‘, ‘find_elements‘, ‘find_elements_by_class_name‘, ‘find_elements_by_css_selector‘, ‘find_elements_by_id‘, ‘find_elements_by_link_text‘, ‘find_elements_by_name‘, ‘find_elements_by_partial_link_text‘, ‘find_elements_by_tag_name‘, ‘find_elements_by_xpath‘, ‘get_attribute‘, ‘id‘, ‘is_displayed‘, ‘is_enabled‘, ‘is_selected‘, ‘location‘, ‘location_once_scrolled_into_view‘, ‘parent‘, ‘rect‘, ‘screenshot‘, ‘screenshot_as_base64‘, ‘screenshot_as_png‘, ‘send_keys‘, ‘size‘, ‘submit‘, ‘tag_name‘, ‘text‘, ‘value_of_css_property‘]

a.get_attribute()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: get_attribute() takes exactly 2 arguments (1 given)
a.get_attributes
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: ‘WebElement‘ object has no attribute ‘get_attributes‘
a.id
u‘{14bf9be1-05c9-440f-adc8-2be8ac5696aa}‘
a.is_displayed()
True
a.is_enabled()
True
a.is_selected
<bound method WebElement.is_selected of <selenium.webdriver.remote.webelement.WebElement (session="f57849aa-5174-4dea-93c1-030e4fbf21f8", element="{14bf9be1-05c9-440f-adc8-2be8ac5696aa}")>>
a.is_selected()
False
a.location
{‘y‘: 29, ‘x‘: 8}
location_once_scrolled_into_view
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name ‘location_once_scrolled_into_view‘ is not defined
a.location_once_scrolled_into_view
{u‘y‘: 29, u‘x‘: 8}
a.parent
<selenium.webdriver.firefox.webdriver.WebDriver (session="f57849aa-5174-4dea-93c1-030e4fbf21f8")>
a.parent()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: ‘WebDriver‘ object is not callable
a.parent
<selenium.webdriver.firefox.webdriver.WebDriver (session="f57849aa-5174-4dea-93c1-030e4fbf21f8")>
a.rect
{u‘y‘: 29, u‘x‘: 8, u‘height‘: 21, u‘width‘: 62}
a.screenshot(‘e:\\a.png‘)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 405, in screenshot
    png = self.screenshot_as_png
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 392, in screenshot_as_png
    return base64.b64decode(self.screenshot_as_base64.encode(‘ascii‘))
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 382, in screenshot_as_base64
    return self._execute(Command.ELEMENT_SCREENSHOT)[‘value‘]
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 454, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
    value = json.loads(value_json)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
a.screenshot_as_png
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 392, in screenshot_as_png
    return base64.b64decode(self.screenshot_as_base64.encode(‘ascii‘))
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 382, in screenshot_as_base64
    return self._execute(Command.ELEMENT_SCREENSHOT)[‘value‘]
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 454, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
    value = json.loads(value_json)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
a.screenshot_as_png(‘e:\\a.png‘)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 392, in screenshot_as_png
    return base64.b64decode(self.screenshot_as_base64.encode(‘ascii‘))
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 382, in screenshot_as_base64
    return self._execute(Command.ELEMENT_SCREENSHOT)[‘value‘]
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 454, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 102, in check_response
    value = json.loads(value_json)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
a.size()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: ‘dict‘ object is not callable
a.size
{‘width‘: 62, ‘height‘: 21}
a.tag_name
u‘a‘
a.text
u‘link to a‘
a.value_of_css_property(property_name)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name ‘property_name‘ is not defined
a.get_attribute(‘href‘)
u‘http://www.test1.com/a.php‘

时间: 2024-11-05 13:40:16

webdriver函数的相关文章

selenium python (一) 开发环境搭建

1.工具下载: python工具共包括三个:python.setuptools.pip ²  python:http://python.org/getit/     python开发环境: ²  setuptools:http://pypi.python.org/pypi/setuptools/ python的基础包工具: ²  pip:http://pypi.python.org/pypi/pip   python的安装包管理工具: 2.windows环境安装 第一步:安装python2.7,

【Selenium WebDriver】元素定位函数 FindElement

定位Web页面上的元素,用FindElement函数,它可以根据元素的不同属性来快速定位.具体的属性如下: 例子: HTML页面文件: 1 <html xmlns="http://www.w3.org/1999/xhtml" lang="en-us"> 2 <head> 3 <body> 4 <form name="loginForm"> 5 <label for="username

查看webdriver针对浏览器的一些函数

在用webdriver对浏览器进行操作时,很多操作并不是那么好找,后来在朋友的推荐下可以用下面的方法来寻找针对浏览器的一些操作,函数或属性等,这样方便我们可以查找一些方法去完成我们要的操作. 下面是查看的方法: from selenium import webdriver browser = webdriver.Firefox()for key in dir(browser): print key 打印的结果如下图所示: 说明,首先要知道dir()的用法,通过查询我们可以知道解释如下: (你可以

selenium2 webdriver 常用的python 函数

新建实例driver = webdriver.Chrome() 1.通过标签属性Id查找元素 方法:find_element_by_id(element_id) 实例:driver.find_element_by_id("iptUsername") 2.通过标签属性name查找元素 方法:find_element_by_name(element_name) 实例:driver.find_element_by_id("inputPwname") 3.通过标签Xpath

在Selenium Webdriver中使用XPath Contains、Sibling函数定位

前言 在一般情况下,我们通过简单的xpath即可定位到目标元素,但对于一些既没id又没name,而且其他属性都是动态的情况就很难通过简单的方式进行定位了. 在这种情况下,我们需要使用xpath1.0内置的函数来进行定位,下面我们重点讨论一下3个函数: Contains Sibling Contains函数 通过contains函数,我们可以提取匹配特定文本的所有元素. 例如在百度首页,我们使用contains定位包含"新闻"文本的元素. baidu_news.png "//d

webdriver常用函数总结

#1 创建浏览器对象 driver = webdriver.Chrome() #2 设置隐式等待10秒 driver.implicitly_wait(10) #3 最大化浏览器窗口 driver.maximize_window() #4 打开网页 driver.get("http://uri") #5 滚动屏幕 #5.1 滚动指定像素 js="var q=document.documentElement.scrollTop=200"driver.execute_sc

简单把webdriver的find_element方法写成函数

__author__ = 'jyd' from selenium.webdriver.common.by import By #driver webdriver实例化对象 #element 查询元素的方法如id,name,xpath #value 元素的值 def find_element(driver,element,value): element=element.upper() element_type=getattr(By,element) element_object=driver.fi

ORACLE/SQL用函数进行每年,每月,每周,每日的数据汇总

15/03/21  用函数进行每年,每月,每周,每日的数据汇总 假设一个销售明细表 sale_detail 含有 国家(country),销售时间(sale_time),销售额(sale_money)..等等 需要用到求和函数 SUM()和分组子句 GROUP BY   按国家和年份分组进行求和汇总(对每一个国家的每一年进行求和) 有两种语句形式: 每年汇总 1.表格形式例如: 国家 年份 销售额 巴西 2014 500000000000 方式一: SELECT  S.country  as 国

Selenium webdriver 学习总结-元素定位

Selenium webdriver 学习总结-元素定位 webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要高些,使用id,name属性定位元素是最可靠,效率最高的一种办法. 1.工具选择:在我们开发测试脚本的过程中各个浏览器给我们也提供了方便定位元素的工具,我比较喜欢使用firefox的firebug工具,也是目前很多开发测试人员比较热衷的选择,原因是firefox是唯一能够集成selenium IDE