通过生成的测试页面window.showmodaldialog

2024-05-15 02:37:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个通过javascript生成页面的网站window.showmodaldialog. 在使用seleniumide和firefox时,我被迫在javascript中插入一个新函数,以从对话框convert返回值window.showmodaldialog到打开新窗口你说

driver.execute_script("function setRetVal(mval) { window.myreturnval = mval;  }")
driver.execute_script("window.showModalDialog = function( sURL,vArguments, sFeatures) { if(window.myreturnval!=null) { var winarg = window.myreturnval; window.myreturnval = null; return winarg; } modalWin = window.open(sURL, vArguments, sFeatures); return false; }")

并修改onbeforeupload以返回结果。在

^{pr2}$

我现在正在尝试转换为python+selenium webdriver以进行测试。我真的不想在测试期间注入新的javascript。问题是

driver.find_element_by_id("MainContent_buttonAccountLookup").click()

触发此代码

<a href="#" id="MainContent_buttonAccountLookup" 
    onclick="javascript:callLookup(&#39;
            Account&#39;,&#39;&lt;
            %=textBoxAccountName.ClientID %>&#39;,&#39;&lt;%=hiddenFieldAccountId.ClientID %>&#39;)
            ;return false;">
    <img alt="Account Lookup" src="../Images/search.GIF" border="0" />
</a>

在窗口关闭之前,它不会将控制释放回python脚本。在

如何启动一个单击,以便可以控制新窗口,执行步骤并关闭它?在


Tags: executereturndriverscriptfunctionjavascriptwindownull
1条回答
网友
1楼 · 发布于 2024-05-15 02:37:07

打开新窗口后,您可以切换到该窗口:

current_window = driver.current_window_handle
for handle in driver.window_handles:
    if handle != current_window:
        driver.switch_to_window(handle)

// perform actions
// close window

driver.switch_to_window(current_window)

相关问题 更多 >

    热门问题