selenium element wait (1)

1. Eighteen positioning methods

Eight commonly used:

1. id positioning: find_element_by_id(self, id) 2.name positioning: find_element_by_name(self, name) 3.class positioning: find_element_by_class_name(self, name) 4.tag positioning: find_element_by_tag_name(self, name) 5.link positioning: find_element_by_link_text (self, link_text) 6.partial_link positioning find_element_by_partial_link_text(self, link_text) 7.xpath positioning: find_element_by_xpath(self, xpath) 8.css positioning: find_element_by_css_selector(self, css_selector) These eight are plural forms : 9.id plural positioning find_elements_by_id (self, id_) 10.name plural positioning find_elements_by_name(self, name) 11.class plural positioning find_elements_by_class_name(self, name) 12.tag plural positioning find_elements_by_tag_name(self, name) 13.link plural positioning find_elements_by_link_text(self, text)














14.partial_link plural positioning find_elements_by_partial_link_text(self, link_text) 15.xpath plural positioning find_elements_by_xpath(self, xpath) 16.css plural positioning find_elements_by_css_selector(self, css_selector special two kinds: find_element(self, by='id', value=None ) find_elements(self, by='id', value=None)




2. Elements and elements are stupidly indistinguishable

1. The element method is positioned to be singular, and it is directly positioned to the element

2. The elements method is plural. Anyone who has studied English knows that it locates a group of elements and returns a list queue .

3. You can use the type() function to view the data type

4. Print the returned content to see what is different

Three, elements positioning method

1. The usage of find_element() has been mentioned in the previous article , see here:

2. Here we focus on how to use the elements method to locate elements. When there are multiple elements with the same attributes on a page, then the attributes of the parent element are also blurred, which is not easy to locate.

Don't be afraid at this time, change your thinking, don't think about locating it once, you can first find the elements with the same attribute, and just take the corresponding number.

4. Reference code

# coding:utf-8 from selenium import webdriver driver = webdriver.Firefox() driver.get("http://www.baidu.com") #Here is a single id positioned element = driver.find_element_by_id("kw") print type(element) print element #The positioning here is multiple class elements = driver.find_elements_by_class_name("mnav") print type(elements) print elements #css syntax used here s = driver.find_elements("css selector", " . mnav") # ' map ' prints in the fourth position s[3].text s[3].click() #This is also possible # driver.find_elements("css selector",".mnav")[3].click()

















 

Guess you like

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