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‘