2016-10-19 86 views
0

我正在嘗試使用webdriver(python)「重置」Chrome瀏覽器。我在做什麼是:webdriver + reset Chrome

司機= webdriver.Chrome()

driver.get( '鉻://設置/ resetProfileSettings')

上面所示的彈出與'重置' 按鈕,並使用我找不到它

driver.find_element_somehow

請幫我找到一種方法來點擊'重置'按鈕。

注意:我還試圖擦除'〜/ .config/google-chrome /'中的所有文件,但這些文件並不滿足需求。

回答

0

找到解決方案,希望能幫助別人。 它是在iframe中,所以我做了:

driver.switch_to_frame('settings') 
0
driver = webdriver.Chrome() 
main_window_handle = None 
while not main_window_handle: 
    main_window_handle = driver.current_window_handle 
popup_handle = None 
while not popup_handle: 
    for handle in driver.window_handles: 
     if handle != main_window_handle: 
      popup_handle = handle 
      break 
driver.switch_to.window(popup_handle) 
driver.find_element_by_xpath(u'XPATH OF RESET BUTTON').click() 
driver.switch_to.window(main_window_handle) 

我覺得switch_to.window(handle)最近被棄用,所以不是說,使用方法:

switch_to_window(handle) 
+0

不幸的是,硒仍然無法找到元素並引發異常 – bay