尝试单击外部按钮>用subming()方法在硒webdriver中标记

发布于 2025-02-04 02:47:28 字数 1031 浏览 3 评论 0原文

使用Selenium webdriver的crist()获取org.openqa.selenium.javascriptexception而不是nosuchelementException(根据文档),如果给定的元素不在形式之内,则使用selenium webdriver forg.openqa.selenium.javascriptexception获取org.openqa.selenium.javascriptexception时,如果给出的元素不在code

是代码时

public void setup() {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    System.out.println("Execution Starts");
    // Setting chrome driver property and opening chrome browser
    System.out.println("Browser opened.");
    // We need to downcast WebDriver reference varaible to use JavascriptExecutor methods
    
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      // identify elements
      driver.get("https://www.youtube.com/");
      // submitting form with click()
      driver.findElement(By.xpath("//ytd-button-renderer[@class='style-scope ytd-masthead style-default size-default']//yt-icon[@class='style-scope ytd-button-renderer']")).submit();
}

While clicking on button which is outside form tag using submit() of selenium webdriver getting org.openqa.selenium.JavascriptException instead of NoSuchElementException(as per the documentation) If the given element is not within a form

following is the code

public void setup() {
    WebDriverManager.chromedriver().setup();
    driver = new ChromeDriver();
    driver.manage().window().maximize();
    System.out.println("Execution Starts");
    // Setting chrome driver property and opening chrome browser
    System.out.println("Browser opened.");
    // We need to downcast WebDriver reference varaible to use JavascriptExecutor methods
    
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      // identify elements
      driver.get("https://www.youtube.com/");
      // submitting form with click()
      driver.findElement(By.xpath("//ytd-button-renderer[@class='style-scope ytd-masthead style-default size-default']//yt-icon[@class='style-scope ytd-button-renderer']")).submit();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文