2017-10-18 55 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

    相关问题