Get the By locator of an already found WebElement

前端 未结 6 1242
眼角桃花
眼角桃花 2020-12-15 17:57

Is there an elegant way to get the By locator of a Selenium WebElement, that I already found/identified?

To be clear about the question: I want the

6条回答
  •  自闭症患者
    2020-12-15 18:29

    Answer is No. You cannot extract a By from a previously found WebElement by default.

    That being said - it's possible to implement a custom solution, but Selenium does not offer this out-of-the-box.

    Consider the following, on "why"..

    By by = By.id("someId");
    WebElement e = driver.findElement(by);
    

    you already have the By object, so you wouldn't need to call something like e.getBy()

提交回复
热议问题