Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 网页元素似乎对Selenium不可见_Java_Selenium_Xpath_Selenium Webdriver_Selenium Ide - Fatal编程技术网

Java 网页元素似乎对Selenium不可见

Java 网页元素似乎对Selenium不可见,java,selenium,xpath,selenium-webdriver,selenium-ide,Java,Selenium,Xpath,Selenium Webdriver,Selenium Ide,我正在尝试单击网页上标记为“浏览”的按钮的/sendKeys,无论我尝试了什么,Selenium都找不到它 使用Selenium的IDE,我可以收集以下信息: id=uploadField name=uploadField css=#uploadField dom:name = document.uploadForm.uploadField xpath:attributes = //input[@id='uploadField'] xpath:idRelative = //div[@id='br

我正在尝试单击网页上标记为“浏览”的按钮的/sendKeys,无论我尝试了什么,Selenium都找不到它

使用Selenium的IDE,我可以收集以下信息:

id=uploadField
name=uploadField
css=#uploadField
dom:name = document.uploadForm.uploadField
xpath:attributes = //input[@id='uploadField']
xpath:idRelative = //div[@id='browseBtnContainer']/form/input[4]
dom:index = document.uploadForm.elements[3]
xpath:position = //input[4]
我已经尝试了以下所有方法。序列,所有这些序列都会抛出一个
NoTouchElementException
。只有一个iframe,我尝试切换到iframe,但没有成功

WebElement browse = driver.findElement(By.id("uploadField"));
WebElement browse1 = driver.findElement(By.name("uploadField"));
WebElement browse2 = driver.findElement(By.cssSelector("#uploadField"));
WebElement browse3 = driver.findElement(By.cssSelector("uploadField")); // just in case
WebElement browse4 = driver.findElement(By.xpath("uploadField")); // attributes
WebElement browse5 = driver.findElement(By.xpath("//div[@id='browseBtnContainer']/form/input[4]")); // idrelative
WebElement browse6 = driver.findElement(By.xpath("//input[4]")); // position
代码的容器部分让我感到困惑。我不知道如何访问容器中的元素,我在google上找到的任何东西都告诉我使用xpath,而我似乎找不到xpath

我是否错误地使用了By.xpath?如何生成网页上每个元素的列表? 以下是相关的HTML源代码:

   <div id="ext-comp-1022" class=" x-panel x-border-panel" style="left: 0px; top: 0px; width: 1077px;">
      <div id="ext-gen27" class="x-panel-bwrap">
         <div id="ext-gen28" class="x-panel-body x-panel-body-noheader"     style="overflow: auto; width: 1075px; height: 502px;">
            <div id="ext-comp-1023" class=" x-panel x-panel-noborder">
               <div id="stepOnePanel"/>
               <div id="stepTwoPanel"/>
               <div id="stepThreePanel"/>
               <div id="stepOnePanel" class="step-container" style="margin:20px 20px 20px 30px;">
                 <div class="step-title" style="background-color:transparent;background-repeat:no-repeat;background-position:top left;background-image:url(/assets/icons/medium/icon-1.png );padding:12px 0px 0px 50px;height:30px;font-weight:bold;">Start by selecting the ZIP file which contains your images (20MB max)</div>
                <div id="ext-gen71" style="padding-left:70px;overflow:auto;">
                      <div id="ext-comp-1024" class=" x-panel x-panel-noborder">
                         <div id="ext-gen74" class="x-panel-bwrap">
                            <div id="ext-gen75" class="x-panel-body x-panel-body-noheader x-panel-body-noborder">
                                <div style="padding-top:2px">
                                   <div id="browseBtnContainer" style="float:left;width:85px;margin-top:-2px">
                                     <table id="browseBtn" class="x-btn stepBtn x-btn-noicon x-btn-over" cellspacing="0" style="width: 79px;">
                                     <form enctype="multipart/form-data" target="hiddenUploadFrame" method="post" action="/uploader/upload?actingAsUserId=pleach&currentAccountId=bmwofreading&uploadAccountId=bmwofreading&ccmode=multiwindow" name="uploadForm">
                                         <input id="doNotResize" type="checkbox" style="display:none" value="true" name="doNotResize"/>
                                         <input id="pdfConvert" type="checkbox" style="display:none" value="true" name="pdfConvert"/>
                                         <input type="hidden" value="false" name="previewNeeded"/>
                                         <input id="uploadField" type="file" size="1" style="position: absolute; top: 0px; left: -19px; opacity: 0; cursor: pointer; height: 22px;" name="uploadField"/>

首先选择包含图像的ZIP文件(最大20MB)
尝试以下方法

driver.findElement(By.xpath("//input[@id='uploadField']")).click();

根据提供的HTML,我们可以使用id或名称直接尝试。如果只查找xpath,请尝试下面的相对xpath

 //input[@id='uploadField']
如果直接单击不起作用,请尝试操作。首先移动到元素,然后尝试单击。我希望这种方式在大多数情况下对我有帮助和效果

Actions move=new Actions(driver);
    move.moveToElement(driver.findElement(By.xpath("//input[@id='uploadField']"))).click().build().perform();
最后,您可以尝试使用javascript执行器

WebElement element = driver.findElement(By.id("uploadField"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
谢谢,,
Murali

您需要切换到
框架
,以便与其中的元素交互

driver.switchTo.frame("id"); //using the frame id attribute
// or
driver.switchTo.frame("name"); //using the frame name attribute
// or
WebElement frame = driver.findElement(...);
driver.switchTo.frame(frame); //using the frame as WebElement
然后切换回去

driver.switchTo().defaultContent();

请提供HTMLcode@muraliseleniumtrainer我已经添加了相关的HTML编码,您可以添加示例url来复制此问题吗;在单击元素之前。。。如果不工作,则尝试驱动程序.switchto().frame(1);