Html Chrome inspect,无法通过我刚才复制的xpath定位元素

Html Chrome inspect,无法通过我刚才复制的xpath定位元素,html,google-chrome,web,selenium-webdriver,xpath,Html,Google Chrome,Web,Selenium Webdriver,Xpath,我在页面上动态弹出一个微调器图标,指示页面正在加载,我需要检测它何时消失(这一点对我来说很清楚) 每次我在google chrome inspect中点击这个微调器,然后按copy xpath,我都会得到这个: /html/body/vr-root/vr-route-handler/vr-layout/mat-sidenav-container/mat-sidenav-content/div/mat-sidenav-container/mat-sidenav-content/div/div/bs

我在页面上动态弹出一个微调器图标,指示页面正在加载,我需要检测它何时消失(这一点对我来说很清楚)

每次我在google chrome inspect中点击这个微调器,然后按copy xpath,我都会得到这个:

/html/body/vr-root/vr-route-handler/vr-layout/mat-sidenav-container/mat-sidenav-content/div/mat-sidenav-container/mat-sidenav-content/div/div/bs-campus/div/div/bs-data-grid/div/div[2]/mat-spinner/svg/circle
但当我试图找到这个元素时(即使在Chrome inspect tool按下CTR+F的内部),它也找不到它

有什么不同的方法来定位它吗?我曾尝试使用相对xpath搜索它,但也失败了:

.//div/mat-spinner
编辑:添加图片

编辑2:当我在Chrome Inspect->Source->pause script execution中暂停页面时,我可以通过以下方式在Chrome Inspect中搜索并找到(ctr+f)元素:

.//mat-spinner
但当页面运行时(元素仍然可见),无法找到它

尝试使用webdriver访问时出现错误日志

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: .//div/mat-spinner (tried for 10 second(s) with 500 milliseconds interval)
        at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:113)
        at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:283)
        at base.StaticSeleniumDriver.getWebElement(StaticSeleniumDriver.java:362)
        at steps.BaseSteps.debugDrawSpinner(BaseSteps.java:55)
        at ?.Given Debug draw spinner(Campus.feature:190)
      Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: .//div/mat-spinner
      For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
      Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
      System info: host: 'BANNB061', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
      Driver info: driver.version: StaticSeleniumDriver
使用以下代码:

WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xpath)));

这是我在量角器中得到的一个解。 我的逻辑是在与网站交互后检查spinner是否存在。 示例:单击元素,键入一些文本,页面导航..弹出窗口等。。 你可以找到合适的地方放它。 希望对您有所帮助,您可以将其应用于任何语言。selenium API很常见

注意,如果找到了//mat微调器,请将其用作元素的xpath

export async function handleSpinner() {
    console.log('Checking if loading spinner is present on the page.');

    let spinner = element(by.css('div.spinner'));
    try {
        // setting minimal timeout to search for the element
        await browser.manage().timeouts().implicitlyWait(500);

        // trigger check if there is such element on the page. will throw exception if not present
        await spinner.getWebElement();

        console.log('Spinner has been found.. waiting.... up to 10 seconds.');
        await browser.wait(ExpectedConditions.invisibilityOf(spinner), 10000, 'Spinner is still present...');
        console.log('Spinner has disappeared.');
    } catch (ex) {
        // spiner is not present so ignore the exception
    } finally {
        // Setting browser implicit timeout back to the original configuration.
        await browser.manage().timeouts().implicitlyWait(10000);
    }
}

共享您的代码。当spinner可见时,也尝试单击页面上的任何元素并检查异常-日志中可能存在spinner的HTML(也共享此HTML)当您查找该元素时,该元素是否可见。它是如何显示和隐藏的?您使用什么技术?@Andersson抱歉,我无法共享整个HTML(其来源于工作)不幸的是,我指的是带有微调器和用于处理的代码的
div
HTMLit@kamentk我正在使用SeleniumWeb驱动程序创建自动化测试,但现在它不是很相关,主要问题是:1.我确保元素可见(微调器)2.我使用chrome inspection工具复制其xPath 3.我确保元素再次可见(微调器)4.当元素仍然可见时,我在chrome inspection工具中按CTR+F,用我以前复制的xPath搜索元素,但即使xPath相同,它也没有检测到它。谢谢