2017-10-18 85 views
1

OS按鈕:OSX的MacOS塞拉利昂10.12.6無法點擊置於iframe內的Safari瀏覽器與硒

硒版本:3.6.0

瀏覽器:Safari瀏覽器

瀏覽器版本: 11.0.1(12604.3.2)

預期行爲 - 點擊()行爲應在位於Safari瀏覽器的iframe中的按鈕工作

實際行爲 - 無在Safari瀏覽器中操作時執行button.click()動作

步驟來重現 -

  1. 打開Safari瀏覽器
  2. 訪問Web應用程序登錄屏幕
  3. 輸入有效的憑據,點擊登錄按鈕,彈出最多出現
  4. 切換到iframe的
  5. 點擊按鈕放在一個iframe

單擊按鈕時無動作。相同的代碼在其他瀏覽器(瀏覽器,Mozilla,IE11)

下面做工精細是代碼:

SafariOptions options = new SafariOptions(); 
options.setUseCleanSession(true); 
driver = new SafariDriver(options); 
driver.manage().window().maximize(); 
driver.get("testurl"); 
driver.findElement(By.id("UN")).sendKeys("admin"); 
driver.findElement(By.id("UN")).sendKeys("admin$"); 
driver.findElement(By.id("Login")).click(); 
driver.switchTo().frame(driver.findElement(By.xpath("//*[starts-with(@class,'dijitDialog') and contains(@style,'z-index: 950;')]//*[starts-with(@id,'AxDojo_Dialog_frame')]"))); 
driver.findElement(By.xpath("//*[@id='ButtonPlaceHolder']/button[2]")).click(); 

在執行最後一步沒有動作。 作爲變通發現下面的代碼

driver.findElement(By.xpath("//*@id='ButtonPlaceHolder']/button[2]")).sendKeys(Keys.ENTER); 

執行點擊按鈕的替代,但像這樣的,我們需要在很多方面改變,硒是獨立於瀏覽器和維護代碼的瀏覽器的聰明是單調乏味的任務給我們。請任何人都可以看看這個問題。

請在iframe中查找HTML代碼。

<iframe id="AxDojo_Dialog_frame_1508320744505" name="AxDojo_Dialog_frame_1508320744505" style="border: 0px; width: 605px; height: 159px;" width="605" height="136px" scrolling="auto" frameborder="0" src="about:blank" axpageload="1"></iframe> 
#document 
<!DOCTYPE html> 
<html style="overflow-y: hidden"><head> 
<title>Login</title> 
<link href="../AxCommon/Styles/ECDefault/main.css" type="text/css" rel="stylesheet"> 
<script language="javascript" type="text/javascript" src="../Packages/Scripts/JQuery/jQuery.js"></script> 
<script type="text/javascript" language="javascript" src="../AxCommon/Scripts/AxSystemBroadcast.js"></script> 
<script type="text/javascript" src="../AxCommon/Scripts/AxMyParent.js"></script> 
<script type="text/javascript" src="./Scripts/AxDialog.js?v=14082015"></script> 
<style type="text/css"> 
    .DialogBtn{width: 80px; font-size: 10pt;white-space:nowrap;} 
    .DialogCustomBtn{font-size: 10pt;white-space:nowrap;} 
    #popupMandatoryDiv { display:none;position:relative;height:auto;background:#FFFFFF;z-index:999999;overflow:auto;border:1px solid black;padding:5px 20px 10px 18px;font-size:12px;} 
    li {list-style: none; } 
    /*li:before {content:'\2022'; display: block; position: relative; max-width: 0px; max-height: 0px; left: -13px; top: -4px; color: red; font-size: 20px;padding-right: 5px;}*/ 
    li:before {content:'\2217'; display: block; position: relative; max-width: 0px; max-height: 0px; left: -13px; top: -2px; color: red;font-weight:bold} 
</style> 
</head> 
<body> 
    <div id="divMask" style="height: auto; width: auto;"> 
     <table id="Table1" cellspacing="6" cellpadding="4" border="0"> 
      <tbody><tr> 
       <td rowspan="3" style="width: 3px; height: 5px" valign="top" align="center"></td> 
       <td colspan="2" valign="top" align="center" height="10"></td> 
      </tr> 
      <tr style="width:100%"> 
       <td valign="top" align="center" width="10%"> 
        <img id="IconImage" src="../AxCommon/Images/28 information.gif"> 
       </td> 
       <td valign="middle" align="left" height="5" width="90%"> 
        <div id="divPrompt" align="left" style="DISPLAY: block; FONT-SIZE: 9pt; OVERFLOW: hidden; DIRECTION: ltr;">You are already logged into Excelicare in other active session(s). Please choose one of the options below:</div> 
       </td> 
      </tr> 
      <tr style="width: 100%; display: none;"> 
       <td valign="top" align="center" width="10%"> 
       </td> 
       <td valign="top" align="left" height="5" width="90%"> 
        <div id="popupMandatoryDiv" align="left" style="DISPLAY: block; FONT-SIZE: 9pt; OVERFLOW: auto; DIRECTION: ltr;display:none"> 
        </div> 
       </td> 
      </tr> 
      <tr> 
       <td valign="middle" align="center" colspan="2" style="padding-top: 10px"> 
        <div id="ButtonPlaceHolder"><button class="DialogCustomBtn" onclick="AxSysF_CloseWindow(6)">Open new session/<br>end other session(s)</button>&nbsp;&nbsp; 
        <button class="DialogCustomBtn" onclick="AxSysF_CloseWindow(7)">Open new session/<br>retain other session(s)</button>&nbsp;&nbsp; 
        <button class="DialogCustomBtn" onclick="AxSysF_CloseWindow(0)">Cancel login<br>&nbsp;</button>&nbsp;&nbsp;</div> 
       </td> 
      </tr> 
      <tr id="trchkPlaceHolder" style="visibility: hidden; display: none;"> 
       <td>&nbsp;</td> 
       <td valign="middle" align="left" colspan="3" id="tdchkPlaceHolder"> 
        <div id="checkPlaceHolder"></div> 
       </td> 
      </tr> 
     </tbody></table> 
     <div> 
      <br> 
      <div id="lblInfo" style="display: block;"><b>Note : </b> If you choose to <i>Open new session/end other session(s)</i> any unsaved data in the other session(s) will be lost.</div> 
     </div> 
    </div> 
    <input id="hdnTitle" type="hidden" value="Login"> 

<script type="text/javascript"> 
    var strProductType = '<%=System.Configuration.ConfigurationSettings.AppSettings("ProductType")%>'; 
    strModulePageName = 'frmdialog'; 
    $(document).ready(function() { PageLoaded();setTimeout('self.focus()', 10);}); 
    function setCallback(CallbackFn) { 
     _CallbackFn = CallbackFn; 
    } 
    document.oncontextmenu = function (event) {return false;}; 
</script> 

</body></html> 

Picture1

Picture2

JavaScript Console when application opened in Safari Private mode

+0

您可以擴展我們感興趣的'

+0

我想這是關於Safari私人模式的安全策略。你可以用Safari私人模式打開你的網站,看看Develop> JavaScript Console?有沒有錯誤? – Buaban

+0

@DebanjanB我在我的問題中添加了HTML代碼片段,並共享了另一個屏幕截圖,擴大了

回答

0

按照您提供的屏幕截圖/ HTML,需要在你的代碼塊做一些修改如下:

  1. 的行:

    driver.switchTo().frame(driver.findElement(By.xpath("//*[starts-with(@class,'dijitDialog') and contains(@style,'z-index: 950;')]//*[starts-with(@id,'AxDojo_Dialog_frame')]"))); 
    

雖然外HTML元素確實具有class屬性作爲dijitDialogPaneContent但不具有style屬性作爲z-index: 950;

  • 線:

    driver.findElement(By.xpath("//*[@id='ButtonPlaceHolder']/button[2]")).click(); 
    
  • 由於使用的是xpath索引例如button[2]xpath變得脆弱和易碎。我寧願擴大<button>標籤,並使用<span>或其他任何標籤/文本來構建獨特的css/xpath

  • 繼上述2的觀察,你可以使你的代碼中的一些細微的變化如下:

    driver.switchTo().frame(driver.findElement(By.xpath("//div[@class='dijitDialogPaneContent')/iframe[starts-with(@id, 'AxDojo_Dialog_frame')]"))); 
    //clicking the first button 
    driver.findElement(By.xpath("//button[@class='DialogCustomBtn' and contains(.,'end other session(s)')]")).click(); 
    
  • 套內這個裝載順序是恆定的,如下我們xpath會更加通用:

    driver.switchTo().frame(driver.findElement(By.xpath("//div[@class='dijitDialogPaneContent')//following::iframe[1]"))); 
        //clicking the first button 
        driver.findElement(By.xpath("//button[@class='DialogCustomBtn' and contains(.,'end other session(s)')]")).click(); 
    
    +0

    感謝您提供的解決方案。我嘗試了您提供的解決方案,但沒有運氣,點擊不起作用。它的工作時使用sendKeys(Keys.ENTER) – SeJaPy

    相關問題