from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
dr = webdriver.Chrome()
dr.implicitly_wait(20)
url = "https://www.jianshu.com/sign_in"
dr.get(url)
#1、根据id定位
jq_userName = "$('#session_email_or_mobile_number').val('userName')"
dr.execute_script(jq_userName)
sleep(1)
#2、根据Type定位
jq_password = "$(':password').val('password')"
dr.execute_script(jq_password)
sleep(1)
#3.按层次定位
#1)、带有标签
# jq_rememberMe = "$('.remember-btn > input:checkbox').click()"
#2)、不带标签
#jq_rememberMe = "$('.remember-btn > :checkbox').click()"
#3)、不带层次符号
#jq_rememberMe = "$('.remember-btn :checkbox').click()"
#4)选择最后一个标签(input)的元素
#jq_rememberMe = "$('.remember-btn > input:last').click()"
#5)从0开始算,选第n-1个元素 -- eq(索引位)
#jq_rememberMe = "$('.remember-btn > input:eq(0)').click()"
#6)从1开始算,选第n个元素 -- nth-child(顺序)
jq_rememberMe = "$('.remember-btn > input:nth-child(1)').click()"
dr.execute_script(jq_rememberMe)
sleep(1)
#4.根据Class定位
jq_loginButton = "$('.sign-in-button').click()"
dr.execute_script(jq_loginButton)
sleep(3)
dr.quit()