브라우저 창이 bg 인 경우이 행은 작동하지 않습니다. 내가 앞에 내 브라우저 창을두면셀렌 브라우저를 앞에 가져 오는 방법은 무엇입니까?
File "myScript.py", line 1469, in getSignedUrl
EC.element_to_be_clickable((By.XPATH, '//button[contains(., "Watch")]')))
File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 71, in until
raise TimeoutException(message)
TimeoutException: Message: ''
와
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
# available since 2.4.0
from selenium.webdriver.support.ui import WebDriverWait
# available since 2.26.0
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Firefox()
browser.get(someWebPage)
element = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, '//button[contains(., "Watch")]')))
elements = browser.find_elements_by_xpath('//button[contains(., "Watch")]')
if elements:
print 'find watch button',elements
elements[0].click()
그것은 오류 밖으로하지만, 그것은 오류가 밖으로하지 않습니다. 내가 사용해야해서는 안되니? EC.element_to_be_clickable
? 나는 오류를 무시하고 내가 원하는 버튼을 계속해서 시도했지만, 브라우저 윈도우가 백그라운드에 있으면 버튼을 찾을 수 없다고 말합니다. 그래서 내가 그 일을하기 전에 브라우저 창을 전경으로 가져와야한다고 생각합니다.
나는 어떤 사람들이 switchTo()
을 토론하는 것을 보았습니까? 내 브라우저 개체에는 그 방법이 없습니다. 창을 독립적으로 전면 시스템에 가져 오려면 어떻게해야합니까? 감사
테스트 시스템
파이썬 2.7 윈도우 7 64
파이썬 2.6.6에 CentOS 6.4
편집 : 나는
browser.execute_script("window.focus();")
및
# commented out EC.element_to_be_clickable as suggested by alecxe
# element = WebDriverWait(browser, 20).until(
# EC.element_to_be_clickable((By.XPATH, '//button[contains(., "Watch")]')))
print 'sleeping 5'
time.sleep(5)
elements = browser.find_elements_by_xpath('//button[contains(., "Watch")]')
print 'before clicking'
from selenium.webdriver.common.action_chains import ActionChains
hover = ActionChains(browser).move_to_element(elements[0])
hover.perform()
print elements
elements[0].click()
시도
EDIT2 작동하지 : 나는이 문서는 창 BG에 있거나 최소화 할 때, 요소가 "볼 수"없습니다, 그래서이 조건이 충족되지 않습니다 때문에 보인다
class selenium.webdriver.support.expected_conditions.element_to_be_clickable(locator)[source]
An Expectation for checking an element is visible and enabled such that you can click it.
을 확인? 어쨌든 다른 조건을 시도했습니다.
class selenium.webdriver.support.expected_conditions.presence_of_element_located(locator)[source]
An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible. locator - used to find the element returns the WebElement once it is located
이것이 작동하는 것 같습니다. 이전에 나는 조건을 완전히 제거하려고 시도 했었고, i가 오랫동안 "잠깐"(5 초 정도) 기다리지 않았기 때문에 간단히 작동하지 않을 수도 있습니다.
edit3 : 이상하게도 셀렌 2.39 파이썬 2.6.6 파이어 폭스 28 센토 6.4가 설치된 컴퓨터에서 이상하게 똑같은 코드가 브라우저 창을 최소화하여 작동합니다. 하지만 같은 코드가 실패한 다른 두 대의 컴퓨터에서 브라우저 창을 최대화해야하고 버튼이 "가시적"이어야합니다. A. win7 x64 firefox 28 셀렌 2.41 python2.7 B. Fedora 20 firefox 28 셀레늄 2.41 python2.7
당신이 ['move_to_element()'(https를 시도 할 수 있습니다 : //selenium-python.readthedocs .org/ko/latest/api.html # selenium.webdriver.common.action_chains.ActionChains.move_to_element)를 클릭하기 전에? – alecxe
@alecxe하지만 'EC.element_to_be_clickable' 줄에서 이미 오류가 있습니다 (내가 클릭하기 전에), 요소는 None입니다. 어떻게 참조 할 수 있습니까? 페이지 일부 아약스 호출을 사용하여, 나는 버튼이 나타날 때까지 기다려야하지만 그것이 얼마나 오래 기다려도 상관없이 bg에있어, 웹 페이지에 "나타나지"않을 것이고 실제로 브라우저 창에 나타납니다. 나는 그것을 볼 수있다. – Shuman
'EC.element_to_be_clickable' 체크를 제거하고'move_to_element()'를 시도하십시오. – alecxe