2012-07-02 3 views
3

셀렌 웹 드라이버 (Internet Explorer)에서 웹 대화 상자를 처리하고 싶습니다. 나는 파이썬을 사용하고있다.selenium webdriver의 웹 대화 상자로 전환 : Python

내 응용 프로그램에서 아이콘을 클릭하면 텍스트 상자 (Webelements)가 포함 된 웹 대화 상자가 열리고 텍스트를 입력 한 후 저장 버튼을 클릭해야한다. 문제는 포커스가 웹 대화 상자로 전환되었는지 아닌지를 모른다는 것입니다. 여기에 내 코드 여기

driver.find_element_by_xpath("//img[contains(@src,'/images/btn_add.gif')]").click() 
driver.switch_to_alert() 
driver.find_element_by_name("report_cutoff_date").sendkeys("10/31/2010") 

내가 webelement는 같은 이름과 컷오프 날짜가 존재 참고로

Traceback (most recent call last): 
File "C:\Users\vthaduri\workspace\LDC\test.py", line 14, in <module> 
driver.find_element_by_name("report_cutoff_date").sendkeys("10/31/2010") 
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 282, in find_element_by_name 
return self.find_element(by=By.NAME, value=name) 
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 651, in find_element 
{'using': by, 'value': value})['value'] 
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 153, in execute 
self.error_handler.check_response(response) 
File "C:\Python27\lib\site-packages\selenium-2.21.2-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 147, in check_response 
raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.NoSuchElementException: Message: u'Unable to find element with name == report_cutoff_date' 

무엇입니까 오류입니다.

나를 도와 줄 수 있습니까?

답변

8

이 시도 :

parent_h = browser.current_window_handle 
# click on the link that opens a new window 
handles = browser.window_handles # before the pop-up window closes 
handles.remove(parent_h) 
browser.switch_to_window(handles.pop()) 
# do stuff in the popup 
# popup window closes 
browser.switch_to_window(parent_h) 
# and you're back 
0

switchto 문 앞에 지연/대기를 걸 수 있습니까?

+0

행운을. 그게 오지 않아. 여전히 동일한 오류가 발생합니다. – vkrams

1

나는 문제가 다음 코드로 생각 -

driver.switch_to_alert(); 

당신은 첫 번째 클릭() 작업을 수행 할 때 나타나는 또 다른 대화 상자로 전환합니다. 나는 나타나는이 상자가 경고이 아니라고 생각합니다. 당신은 당신은 예를 들어 here을 확인할 수 있습니다

driver.getWindowHandles(); 
driver.switchTo().window(handle); 

를 사용하여 다른 대화 상자로 전환해야 할 수도 있습니다.

관련 문제