无法单击对话框继续选项
Failing to click on Dialog box continue option
我有一个应用程序不断显示对话框消息以单击继续按钮下面是继续会话的代码,它每分钟左右不断出现,这让我很烦。所以我可以不受任何干扰地处理应用程序。所以,我写这个是为了自动化。它找不到这个元素,我也试过注释部分 #EC.alert_is_present() 和 #browser.switch_to().alert().accept()
这两个都不适合我。但是,它登录时没有任何问题,但无法单击不断出现的对话框继续按钮。请帮我解决这个问题。
HTML:
<span class="dijitReset dijitInline dijitButtonText" id="confirmInforDialogActionOk_label" data-dojo-attach-point="containerNode">Continue</span>
代码试验:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from datetime import datetime
from selenium.common.exceptions import TimeoutException
browser = webdriver.Chrome(executable_path=r'D:\Jake\Python\chromedriver.exe')
browser.get('https://testtest.com/');
browser.maximize_window()
browser.find_element_by_name('j_username').send_keys('Jake')
browser.find_element_by_name('j_password').send_keys('Jake@123')
browser.find_element_by_xpath("//a[@class='btn btn-primary btn-block']").click()
App_loaded_one = WebDriverWait(browser,180).until (
EC.presence_of_element_located((By.ID, "userAvatarMenu"))
)
def alertpresent():
App_loaded = WebDriverWait(browser,300).until (
#EC.alert_is_present()
EC.presence_of_element_located((By.ID, 'onfirmInforDialogActionOk_label'))
)
#browser.switch_to().alert().accept()
browser.find_elements_by_id('onfirmInforDialogActionOk_label').click()
print ("Clicked dialog");
print (datetime.now())
while True:
alertpresent()
我在命令提示符下收到以下消息-
> DevTools listening on
> ws://127.0.0.1:53745/devtools/browser/59aa8b6e-1dee-458e-afa5-653052f266aa
> Traceback (most recent call last): File
> "C:\Users\Jake\Desktop\Instances\test.py", line 32, in <module>
> alertpresent() File "C:\Users\Jake\Desktop\Instances\test.py", line 22, in alertpresent
> EC.presence_of_element_located((By.ID, 'onfirmInforDialogActionOk_label')) File
> "C:\Users\Jake\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py",
> line 80, in until
> raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
元素在 Modal Dialog Box so to click on the element with text as Continue instead of presence_of_element_located()
you have to induce for the element_to_be_clickable()
and you can use either of the following :
中
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.dijitReset.dijitInline.dijitButtonText#confirmInforDialogActionOk_label[data-dojo-attach-point='containerNode']"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='dijitReset dijitInline dijitButtonText' and @id='confirmInforDialogActionOk_label'][@data-dojo-attach-point='containerNode']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
我有一个应用程序不断显示对话框消息以单击继续按钮下面是继续会话的代码,它每分钟左右不断出现,这让我很烦。所以我可以不受任何干扰地处理应用程序。所以,我写这个是为了自动化。它找不到这个元素,我也试过注释部分 #EC.alert_is_present() 和 #browser.switch_to().alert().accept() 这两个都不适合我。但是,它登录时没有任何问题,但无法单击不断出现的对话框继续按钮。请帮我解决这个问题。
HTML:
<span class="dijitReset dijitInline dijitButtonText" id="confirmInforDialogActionOk_label" data-dojo-attach-point="containerNode">Continue</span>
代码试验:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from datetime import datetime
from selenium.common.exceptions import TimeoutException
browser = webdriver.Chrome(executable_path=r'D:\Jake\Python\chromedriver.exe')
browser.get('https://testtest.com/');
browser.maximize_window()
browser.find_element_by_name('j_username').send_keys('Jake')
browser.find_element_by_name('j_password').send_keys('Jake@123')
browser.find_element_by_xpath("//a[@class='btn btn-primary btn-block']").click()
App_loaded_one = WebDriverWait(browser,180).until (
EC.presence_of_element_located((By.ID, "userAvatarMenu"))
)
def alertpresent():
App_loaded = WebDriverWait(browser,300).until (
#EC.alert_is_present()
EC.presence_of_element_located((By.ID, 'onfirmInforDialogActionOk_label'))
)
#browser.switch_to().alert().accept()
browser.find_elements_by_id('onfirmInforDialogActionOk_label').click()
print ("Clicked dialog");
print (datetime.now())
while True:
alertpresent()
我在命令提示符下收到以下消息-
> DevTools listening on
> ws://127.0.0.1:53745/devtools/browser/59aa8b6e-1dee-458e-afa5-653052f266aa
> Traceback (most recent call last): File
> "C:\Users\Jake\Desktop\Instances\test.py", line 32, in <module>
> alertpresent() File "C:\Users\Jake\Desktop\Instances\test.py", line 22, in alertpresent
> EC.presence_of_element_located((By.ID, 'onfirmInforDialogActionOk_label')) File
> "C:\Users\Jake\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py",
> line 80, in until
> raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
元素在 Modal Dialog Box so to click on the element with text as Continue instead of presence_of_element_located()
you have to induce element_to_be_clickable()
and you can use either of the following
使用
CSS_SELECTOR
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span.dijitReset.dijitInline.dijitButtonText#confirmInforDialogActionOk_label[data-dojo-attach-point='containerNode']"))).click()
使用
XPATH
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[@class='dijitReset dijitInline dijitButtonText' and @id='confirmInforDialogActionOk_label'][@data-dojo-attach-point='containerNode']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC