页包含此form
<form target="PID297_TGT_FRAME" action="/app/upload/57aa897a64d9" class="form form-default" method="post" enctype="multipart/form-data">
<div>
<input type="hidden">
<input name="PID297_file" class="file-upload" type="file">
<div aria-pressed="false" role="button" class="v-button" tabindex="0">
<span class="v-button-wrap">
<span class="v-button-caption">Import</span>
</span>
</div>
</div>
</form>现在我想上传文件到表单。在搜索堆栈溢出之后,我发现可以向input发送file类型的文件路径。所以我做了这个:
var elem = Driver.FindElement(By.Name("PID297_file")).SendKeys(filePath);不幸的是,我收到了Exception的留言:
Element is not currently visible and so may not be interacted with我的密码有什么问题吗?
发布于 2018-10-11 11:29:29
元素需要是可见的,selenium才能访问它。如果有其他允许文件上传的操作,请首先在selenium代码中执行。
发布于 2018-10-11 12:43:32
这个错误信息..。
Element is not currently visible and so may not be interacted with...implies表示,WebDriver实例无法定位该元素,因为它不可见。
从这条消息中得到的积极结果是所需的元素是存在于HTML DOM中的,而不是可见的,因为它可能不在视口中。
解决方案
在调用SendKeys()之前,需要在Viewport中引入所需的元素,如下所示:
CssSelector:
新WebDriverWait(驱动程序,WebDriverWait)XPath:
新的TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input@class='file-upload‘(WebDriverWait)(驱动程序,包含(@name,’_file‘)).SendKeys(FilePath);https://stackoverflow.com/questions/52758848
复制相似问题