Several common methods of selenium CSS positioning

Source: Internet
Author: User

#-*-coding:utf-8-*-
From selenium import Webdriver
From time import sleep
From Selenium.webdriver.common.action_chains import Actionchains


Driver = Webdriver. Firefox ()

url = "https://www.baidu.com/"
# URL = "http://www.cnblogs.com/yoyoketang/"
Driver.get (URL)

"" Property Locates One "" "
# #通过id
# driver.find_element_by_css_selector ("#kw"). Send_keys (U "blog Park")
# #通过class
# Driver.find_element_by_css_selector (". S_ipt"). Send_keys (U "blog Park")
Additional label filtering is required in the case of excessive #通过标签
# Driver.find_element_by_css_selector ("Span>input:nth-child (2)"). Send_keys (U "blog Park")

# #其他属性
# driver.find_element_by_css_selector ("[name = ' WD ']"). Send_keys (U "blog Park")
# Driver.find_element_by_css_selector ("[autocomplete = ' off ']"). Send_keys (U "blog Park")

"" "CSS Combination positioning two" ""
"" "The writing mode of the parent-child relationship Form.fm>span" "
# driver.find_element_by_css_selector ("Form.fm>span>input.s_ipt"). Send_keys (U "blog Park")
# driver.find_element_by_css_selector ("form.fm>span>input#kw"). Send_keys (U "blog Park")
#
"" To locate a list to take a "" "
# Print Driver.find_element_by_css_selector (". Mnav:nth-child (1)"). Text
# Driver.find_element_by_css_selector (". Mnav:nth-child (1)"). Click ()

"" "CSS logic operation, multi-conditional combination positioning-----Not located, do not know the reason" ""
# Driver.find_element_by_css_selector ("[type= ' text '][name= ' WD ']"). Send_keys (U "blog Park")


Sleep (3)
Driver.quit ()
< Span style= "COLOR: #a5c261" > < Span style= "COLOR: #808080" > < Span style= "COLOR: #808080" > < Span style= "COLOR: #808080" >&NBSP;         

Several common methods of selenium CSS positioning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.