2014-09-25 4 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} 

I 내 스크립트에 다음을 추가해야합니다. x = insertloc.x 및 y = insertloc. 상대적를 제공 y를 나는 그것을 시도했습니다

좌표하지만이 결과입니다 : 내가 솔루션을 둘러보고있다

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

목록에서 dict를 변환하고 결과를 가져옵니다.

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

출력 : 당신이 필요로하는 경우

[316, 364] 
316 
364 

가 이제 좌표를 사용할 수 있습니다.

관련 문제