【问题标题】:Not able to locate the button and use click function: Selenium WebDriver with Java无法找到按钮并使用点击功能:Selenium WebDriver with Java
【发布时间】:2016-09-08 18:42:40
【问题描述】:

我无法在我使用 selenium webdriver 和 java 自动化的网站中找到该按钮并单击它。 有人可以帮忙吗? (使用 CSS 选择器)

下面是按钮的 HTML

<div class="inputWrapper newButton" name="uploadDiv">
<h6 name="fileUpload">
<label for="pdfFileUplod">Upload file</label>
</h6>
<input id="pdfFileUplod" class="fileInput hidden_" type="file" onchange="checkFile = checkFileName(this);" name="uploadFile"/>
</div>

【问题讨论】:

  • 你没有按钮,你有一个file类型的输入。检查这个问题:stackoverflow.com/questions/9726005/…
  • 你能分享你的代码吗,已经试过了??
  • @KirilS。我很欣赏你的回应。我试过了,它不起作用,我也尝试过绝对路径和相对路径。每次我收到相同的错误“org.openqa.selenium.TimeoutException:等待 5 秒后超时”.. 我也给了时间等待,sleep(6000) 它仍然无法正常工作

标签: java css selenium selenium-webdriver


【解决方案1】:

如果你认为文件上传按钮,你有id,所以使用它:

WebElement el = driver.findElement(By.Id("pdfFileUplod"));
el.click()

【讨论】:

    猜你喜欢
    • 2022-12-05
    • 2015-04-25
    • 2016-09-22
    • 2021-11-09
    • 2020-03-16
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多