gpt4 book ai didi

selenium - 无法使用 Selenium Webdriver click() 或 submit() 输入

转载 作者:行者123 更新时间:2023-12-05 01:05:37 25 4
gpt4 key购买 nike

所以我在一个页面上有一个输入元素,我需要点击它才能转到另一个页面。问题是当我在元素上使用 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>

这是我的 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();
}

我也尝试过隔离输入的父 td 并单击它但没有运气。我在这里不知所措。
  • 我需要补充一点,我正在使用 Internet Explorer 驱动程序 (IEDriverServer) 并且在 IE9 浏览器上。不幸的是,这就是该应用程序将运行的所有内容!
  • 最佳答案

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

  • 在单击之前将注意力集中在元素上。

  • ecrButton.click(); // dummy click to focus
    // or ecrButton.sendKeys("\n"); // also tries to focus
    ecrButton.click(); // do your actual click
  • 使用 Actions 中的点击方法类(class)。

  • new Actions(driver).click(ecrButton).perform();
  • 注入(inject) JavaScript 点击

  • JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", ecrButton);

    关于selenium - 无法使用 Selenium Webdriver click() 或 submit() 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21242515/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com