无法使用Selenium Webdriver单击()或submit()输入

Con*_*ner 4 selenium ui-automation selenium-webdriver

所以我在页面上有一个输入元素,我需要点击它去另一个页面.问题是,当我在元素上单击click()或submit()时,没有任何反应.我有一个自定义突出显示方法,所以我可以看到我实际上是正确的元素.由于某些未知原因,click()似乎没有在它上面工作.

这是我正在使用的HTML

<TBODY>
<TR style="" class=" STDLISTROW_O" onmouseover=listMouseOver(this);  onmouseout=listMouseOut(this); saveBG>
<TD class=STDLISTBTN>
<INPUT style="COLOR: " onmouseover="listBtnMouseOver(this);   window.status = this.status_txt;" onmouseout="listBtnMouseOut(this); window.status = '';" onclick=" event.cancelBubble = true;  if (this.getAttribute('clicked') == 'false')  { document.location.href = 'client$.startup?P_CLIENT_ID=7605677'; this.setAttribute('clicked', 'true'); } " value=ECR type=button status_txt="client$.startup?P_CLIENT_ID=7605677" clicked="false" saveBtnBG saveBtnC></TD>
Run Code Online (Sandbox Code Playgroud)

这是我的Selenium/Java方法

public void clickECRButtonWithID(String clientID) {
    log.info("Click the ECR button for the row with client id: " + clientID);
    WebElement idRow = driver.findElement(By.xpath("//td[contains(text(),'"
            + clientID + "')]/ancestor::tr"));
    WebElementExtender.highlightElement(idRow);
    WebElement ecrButton = driver.findElement(By.cssSelector("input[value='ECR']"));
    WebElementExtender.highlightElement(ecrButton);
    ecrButton.click();
}
Run Code Online (Sandbox Code Playgroud)

我也试过隔离输入的父td并点击它没有运气.我在这里不知所措.

  • 我需要补充说我正在使用Internet Explorer驱动程序(IEDriverServer)并且我在IE9浏览器上.不幸的是,所有这个应用程序都将运行!

Yi *_*eng 5

首先尝试其他浏览器,如Firefox和Chrome,以确保您的代码(定位器等)正确无误.然后你可能想尝试一些IE解决方案.

  • 在点击之前关注元素.
ecrButton.click(); // dummy click to focus
// or ecrButton.sendKeys("\n"); // also tries to focus
ecrButton.click(); // do your actual click
Run Code Online (Sandbox Code Playgroud)
  • 使用Actions课堂上的点击方法.
new Actions(driver).click(ecrButton).perform();
Run Code Online (Sandbox Code Playgroud)
  • 注入JavaScript单击
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ecrButton);
Run Code Online (Sandbox Code Playgroud)