我無法使用selenium webdriver關閉jquery對話框。這裏是我的代碼。我正在使用Selenium WebDriver版本:2.44.0,Firefox版本:33.請任何想法。無法使用Selenium Webdriver Python關閉彈出對話框(元素當前不可見,因此可能無法與之交互)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.ui import WebDriverWait
browser = webdriver.Firefox()
browser.get('https://122.155.222.114/ev57/login/login.aspx')
time.sleep(5)
#I use inspect element in firebug
#<div style="float: right; cursor: pointer; display: block;" class="dialog-icon-close" role="button">X</div>
#browser.execute_script('$(".dialog-icon-close").click();')
#This work but maybe not the selenium way.
elem = browser.find_element_by_class_name('dialog-icon-close')
#This produce error
#ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
elem.click()
編輯:我現在用的這個方法,它的工作原理,但也許還不夠好。
#browser.execute_script('$(".dialog-icon-close").click();')
#This work but maybe not the selenium way.
它在一個框架中。 – SiKing