How to check if element contains specific class attribute

前端 未结 7 1739
生来不讨喜
生来不讨喜 2021-02-05 02:09

How can I check if a selenium web element contains a specific css class.

I have this html li element

  • 相关标签:
    7条回答
    • 2021-02-05 02:33

      Use javascript: classList.contains

       WebElement element = By.id("id");
       String className = "hidden";
       JavascriptExecutor js = (JavascriptExecutor) driver;
       Boolean containsClass = js.executeScript("return arguments[0].classList.contains(arguments[1])", element, className);
      
      0 讨论(0)
    提交回复
    热议问题