Javascript Executor没有点击iframe里面的输入 - Selenium

时间:2016-08-29 12:24:33

标签: javascript html google-chrome selenium iframe

点击iframe中的某个输入时,我遇到了selenium的Javascript执行器问题。问题发生 chrome 在IE和FF上正常工作,不知道为什么

这里是html文件:



<iframe id="iframContainer" ng-src="app/docManagement/upload/iframe/iframe.html" src="app/docManagement/upload/iframe/iframe.html">
<!DOCTYPE html>
<html lang="en" dir="{{dir}}" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<script src="jquery-1.9.1.min.js" type="text/javascript">
<script src="uploader.js" type="text/javascript">
<style type="text/css">
</head>
<body class="upload-control">
<div id="drop" class="dragdrop_zone">
<input id="uploader" type="file" multiple="" name="file">
</div>
<script type="text/javascript">
</body>
</html>
 </iframe>
&#13;
&#13;
&#13;

这里是我使用selenium executor点击元素的代码:

 int uploadArea = Driver.GetFirstFrameIndex();
       Driver.Upload_File_Generic(FileUpload);
         try
        {
            Thread.Sleep(2000);
           Driver.SwitchToFrame(uploadArea);
            Initiate_Driver.ClickJSElement(By.Id(AddREsources_IDs.UploadArea),"Uploader",Messages.ElementValidation.Mandatory);
        }
        catch
        {
        }
       Initiate_Driver.GetOutofFrame();


   public static void SwitchToFrame(int index)
    {
        try
        {

            driver.SwitchTo().Frame(index);
        }
        catch
        {
            Messages.NoSuchFrame(FrameName, validation);
        }
    }
  public static void ClickJS(By by, string ElementName)
    {

        IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;

        string _JSCommand = "";

        if (by.ToString().Contains("Id"))
        {
            string ID = by.ToString().Replace("By.Id: ", string.Empty);
            _JSCommand = "document.getElementById('" + ID + "').click();";

        }

        else if (by.ToString().Contains("Name"))
        {
            string Name = by.ToString().Replace("By.Name: ", string.Empty);
            _JSCommand = "document.getElementByName('" + Name + "').click();";
        }


        executor.ExecuteScript(_JSCommand);


    }

再次:问题只发生在Chrome上,但它在IE和FF上工作得非常好。

0 个答案:

没有答案