【问题标题】:Web objects locators for Edge browser?Edge浏览器的Web对象定位器?
【发布时间】:2022-01-26 01:47:59
【问题描述】:

嘿,我是网络自动化的新手,我刚刚开始编写我的场景并使用 java 框架将它们链接到相关步骤:

我为这个按钮尝试了不同的方法:

driver.findElement(By.xpath/className) 

我的代码中总是出现这个异常:

org.openqa.selenium.NoSuchElementException

exemple used: WebElement filter = driver.findElement(By.xpath("//*[@id ='sidebarCollapse']"));
    filter.click();

谁能帮帮我(见附图)?

【问题讨论】:

    标签: java selenium xpath css-selectors webdriverwait


    【解决方案1】:

    到元素上的click(),您可以使用以下任一Locator Strategies

    • cssSelector

      driver.findElement(By.cssSelector("span#sidebarCollapse[title='Filtres de recherche']")).click();
      
    • xpath

      driver.findElement(By.xpath("//span[@id='sidebarCollapse' and @title='Filtres de recherche']")).click();
      

    理想情况下,click() 在您需要为WebDriverWait 诱导elementToBeClickable() 的元素上,您可以使用以下任一Locator Strategies

    • cssSelector

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("span#sidebarCollapse[title='Filtres de recherche']"))).click();
      
    • xpath

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@id='sidebarCollapse' and @title='Filtres de recherche']"))).click();
      

    【讨论】:

    • 你好 DebanjanB,我仍然得到错误:没有这样的元素:无法找到元素:,我尝试了两个定位器 css 和 xpath :(
    猜你喜欢
    • 2015-10-21
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多