【问题标题】:Click an element within section tag单击部分标记内的元素
【发布时间】:2019-08-06 17:36:23
【问题描述】:

元素在标签内,但尝试了很多方法都无法点击它。

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='Login to Register']"))).click();

WebElement element = driver.findElement(By.xpath("//input[@value='Login to Register']"));
JavascriptExecutor jsEx= (JavascriptExecutor)driver;
jsEx.executeScript("arguments[0].click();", element);

这是 html:

<div id="requestRegistrationWidget">
     <a id="requestLocationLogin" href="/user/login?destination=%2Fsearch%2Flocations%2Fwidget%3Fparam1%3D006046-0619_1565278200_11000000%26param2%3D3" class="use-ajax login-popup-form" data-dialog-type="modal">
        <input class="btn btn-primary" style="width: 100% !important;" type="button" value="Login to Register"></input>
    </a>
      <!-- registerSession == 3 and registerAnyActiveSession == 1 case (2) --> 
</div>

【问题讨论】:

  • 可以分享一下网址吗?
  • preview.queenslibrary.org/search/calendar?searchField=*&category=calendar&searchFilter= 只需单击您将看到的任何卡片 快速查看右侧的特定部分不可用。谢谢。
  • preview.queenslibrary.org/search/calendar?searchField=*&category=calendar&searchFilter= " 点击搜索放星点击 ''日历" 单选按钮并点击右侧搜索 只需点击任何卡片即可快速查看右侧特定部分不可行。谢谢。
  • 我无法按照您的上述步骤重现,但您的选择器可能没有选择您认为的内容,这就是它不可点击的原因。
  • 导航 --> 在“捐赠”按钮后单击右上角的搜索,然后将 * 放在“关键字”上,然后选择“日历”单选按钮,然后单击右侧的搜索按钮。之后,单击您将在卡片右侧的“快速查看”窗格中看到的任何卡片,此特定部分我无法单击。-谢谢。 @DMart

标签: java selenium xpath css-selectors webdriverwait


【解决方案1】:

你能试试下面的代码吗?

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.id("requestLocationLogin"))).click();

【讨论】:

  • 选择受众 org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//input[@value='Login注册']"}(会话信息:chrome=75.0.3770.142)有关此错误的文档,请访问:seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'3.141.59',修订:'e82be7d358',时间:'2018- 11-14T08:25:53'
  • 没有这样的元素:无法定位元素:{"method":"xpath","selector":"//input[@value='Login to Register']"}
【解决方案2】:

我想您在 chrome 上遇到了这个问题。 试试这个,它对我有用。

element.sendKeys(Keys.RETURN);

它只是点击元素上的“Enter”按钮。

【讨论】:

    【解决方案3】:

    到元素上的click(),文本为Login to Register,因为该元素是AJAX启用元素,您必须为elementToBeClickable()诱导WebDriverWait和您可以使用以下任一Locator Strategies

    • cssSelector:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.use-ajax.login-popup-form#requestLocationLogin>input.btn.btn-primary[value='Login to Register']"))).click();
      
    • xpath:

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='use-ajax login-popup-form' and @id='requestLocationLogin']/input[@class='btn btn-primary' and @value='Login to Register']"))).click();
      

    【讨论】:

    • xpath 和 cssSelector 已尝试但无法点击 AJAX 元素!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-12
    • 2012-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多