(E) WebDriver API positioning of the positioning element -Link

Essays and records to facilitate their access to fellow travelers.

#------------------------------------------------I ------------------------------------------- dividing line is a shame

  Learning before selenium automation, it is best to learn HTML, CSS, JavaScript and other knowledge, help to understand the principles of operation and positioning elements. About python and selenium install their own search for other information,

Here do not introduced, all examples use python3.6 + selenium execution.

#------------------------------------------------I ------------------------------------------- dividing line is a shame

 

Link positioning method and positioning of several different previously described, it is designed to position the text connection. Baidu code of the boxes connected to several texts follows:

<a href="http://news.baidu.com" target="_blank" class="mnav">新闻</a>

<a href="http://v.baidu.com" target="_blank" class="mnav">视频</a>

<a href="http://tieba.baidu.com" target="_blank" class="mnav">贴吧</a>

 

# Import webdriver module which is used to control the browser 
from Selenium Import webdriver 

Driver = webdriver.Chrome () # instantiated, Google Chrome and specify open 
first_URL = ' http://www.baidu.com ' # define URL accessed 
driver.get (first_URL) # use the get method to access web pages 

element = driver.find_element_by_link_text ( ' news ' ) # Elementary located by Link 
Print (element)

 

The results show:

Because we do not do anything, but all the open automatically open your browser and find elements, find the following figure shows the elements, find_element_by_link_text expressed link to find

 

Guess you like

Origin www.cnblogs.com/lirongyang/p/11457433.html