2014-09-25 320 views
0

我開發的腳本程序來測試我的新的激情的要素座標,這就是結果:得到location_once_scrolled_into_view結果

腳本:

from selenium import webdriver 
selenium.webdriver.common.by import By 
import time 

driver = webdriver.Chrome() 
driver.get('https://www.google.it') 
driver.maximize_window() 

try: 
time.sleep(5) 
insert = driver.find_element_by_id('gbqfq') 
insertloc = insert.location_once_scrolled_into_view 
print insertloc 
finally: 
driver.quit() 

輸出:

{u'y': 316, u'x': 364} 

我需要添加到我的腳本,如: x = insertloc.x和y = insertloc。 Ÿ給出的相對座標

我已經嘗試,但這樣的結果:

Traceback (most recent call last): 
    File "D:\python\selenium\webdriver\googlelocation.py", line 21, in <m 
odule> 
print insertloc.x 
    AttributeError: 'dict' object has no attribute 'x' 

我到處尋找一個解決方案,我也一定發現一個,用代碼來寫英里,工作在字符串上。但我相信有更清潔的東西存在,請幫助我。

回答

0

在列表中轉換字典並獲得結果。

xy = insertloc.values() 
print xy 
y = xy[0] 
x = xy[1] 
print y 
print x 

輸出:

[316, 364] 
316 
364 

現在你可以,如果你需要使用的座標。