Webdriver element location - id and name

element positioning

Element positioning is the core of automated testing. If you want to operate an element, you should first identify this element. webdriver provides a series of element positioning methods, commonly used are the following:

  • id
  • name
  • class name
  • link text
  • partial link text
  • tag name
  • xpath
  • css selector

id and name positioning

Case: Open the Baidu homepage, automatically enter the keyword "Selenium I want to learn by myself" in the search box, and then click the search button to view the search page.
Note: We can view the id and name of the input box and the name of the search button through F12, as shown in the following figure:


The final code is as follows:


problems encountered

Question 1:

During the execution of the code, the following error was encountered: "selenium.common.exception.InvalidArgumentException: Message: Expected [object Undefined] undefined to be a string"


Baidu searched, and the Internet said that the version of webdriver and Firefox browser may be incompatible. My selenium is 3.5.0, the browser driver is: geckodriver (not sure what version), and the Firefox version is: 53.0.3 (64-bit). After I updated the version of geckodriver to v0.18.0 (64-bit), the problem was solved.

Question 2:

During the execution of the code, the following error was encountered: "selenium.common.exceptions.WebDriverException: Message: quit"


My selenium is 3.5.0, the browser driver is: geckodriver version is: v0.18.0 (64 bit) , Firefox version is: 53.0.3 (64 bit). Updating the Firefox version to 54.0 (64-bit) solved the problem.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325411176&siteId=291194637