How to get findElementById method?

大憨熊 提交于 2020-12-27 07:29:41

问题


I loaded Selenium latest version 3.3.1 to my system through maven dependencies. While trying to code, I couldn't get the method findElementById(). Instead, I am getting only old method findElement(). Can anyone help me? Note: In maven, it shows only latest version.


回答1:


add following dependency to maven, do maven clean and maven build

  • Use RemoteWebDriver type while instantiating driver like
    "RemoteWebDriver driver=new FirefoxDriver()" as RemoteWebDriver class has findElementById() method

      < dependency>
      < groupId>org.seleniumhq.selenium</groupId>
      < artifactId>selenium-remote-driver</artifactId>
      < version>3.3.1</version>
     </dependency>
    



回答2:


You should use the method from the class By:

driver.findElement(By.id("element id")) 



回答3:


It depends on language you are using for your automation:

For Java:

driver().findElement(By.id("locator")).click();

For Python:

driverInstance.find_element_by_id("Id Locator").click()


来源:https://stackoverflow.com/questions/43245974/how-to-get-findelementbyid-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!