【问题标题】:Click Record Button at about:tracing through Selenium [duplicate]在 about:tracing through Selenium 单击记录按钮 [重复]
【发布时间】:2019-01-21 16:53:36
【问题描述】:

我正在尝试通过 Google Chrome 中的 Selenium 单击记录按钮。但是我做不到。未找到元素。我尝试过使用 id 和 xpath。他们都没有工作。

WebElement record = driver.findElement(By.id("record-button")); record.click();

HTML代码是

<template id="profiling-view-template">
  <tr-ui-b-info-bar-group></tr-ui-b-info-bar-group>
  <x-timeline-view-buttons>
    <button id="record-button">Record</button>
    <button id="save-button">Save</button>
    <button id="load-button">Load</button>
  </x-timeline-view-buttons>
  <tr-ui-timeline-view>
    <track-view-container id="track_view_container"></track-view-container>
  </tr-ui-timeline-view>
</template>

任何线索将不胜感激。

【问题讨论】:

  • 请分享相关html代码
  • 您将不得不分享更多代码:这是在框架内吗?这是在 shadow-DOM 中吗?有很多 AJAX 吗?
  • 我不确定 AJAX 或 shadow-DOM。但是,您可以通过在 Google Chrome 中打开“chrome://tracing”作为 url 轻松找到它
  • 使用 shadow-DOM。看到这个:stackoverflow.com/q/48286398/3124333
  • 谢谢你.. 它有效。

标签: google-chrome selenium shadow-dom


【解决方案1】:

我可以通过这个访问那个对象

WebElement root1 = driver.findElement(By.tagName("tr-ui-timeline-view")); WebElement shadowRoot1 = expandRootElement(root1); WebElement record1 = shadowRoot1.findElement(By.id("record-button")); record1.click();

public WebElement expandRootElement(WebElement element) { WebElement ele = (WebElement) ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot", element); return ele; }

【讨论】:

    猜你喜欢
    • 2014-07-14
    • 2020-10-16
    • 2022-12-18
    • 2020-11-28
    • 2013-12-24
    • 2021-08-03
    • 2020-01-08
    • 2022-01-09
    • 1970-01-01
    相关资源
    最近更新 更多