gpt4 book ai didi

selenium-webdriver - NoSuchElementException - 无法定位元素

转载 作者:行者123 更新时间:2023-12-04 07:57:47 25 4
gpt4 key购买 nike

我有一个输入框,就像我在这里用来输入我的问题的输入框一样,它的 HTML 是

<body id="tinymce" class="mce-content-body" contenteditable="true" onload="window.parent.tinymce.get('Description').fire('load');" spellcheck="false" style="padding-bottom: 50px; padding-left: 1px; padding-right: 1px; overflow-y: hidden;">
<p>
<br data-mce-bogus="1"/>
</p>
</body>

每次,我都会尝试输入一些文字
@FindBy(xpath="//body[@id='tinymce']") WebElement Category_Body;
Category_Body.sendKeys("Android Smart Phone - 16GB");

我收到错误 -

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//body[@id='tinymce']"}

最佳答案

如果您收到 NoSuchElementException作为您提供的异常(exception),可能有以下原因:-

  • 可能是当您要查找元素时,它不会出现在 DOM 上, 所以你应该执行 WebDriverWait等到元素可见,如下所示:-
    WebDriverWait wait = new WebDriverWait(driver, 10);
    WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("tinymce")));
    Category_Body.sendKeys("Android Smart Phone - 16GB");
  • 可能是这个元素在任何 frame 里面或 iframe .如果是,你需要切换那个 frameiframe在找到如下元素之前:-
    WebDriverWait wait = new WebDriverWait(driver, 10);

    //Find frame or iframe and switch
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("your frame id or name"));

    //Now find the element
    WebElement Category_Body = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("tinymce")));
    Category_Body.sendKeys("Android Smart Phone - 16GB");

    //Once all your stuff done with this frame need to switch back to default
    driver.switchTo().defaultContent();
  • 关于selenium-webdriver - NoSuchElementException - 无法定位元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39190910/

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