selenium基础操作回顾

from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.by import By


self.sle = (By.CSS_SELECTOR,'#user_login')#元素定位,和定位方式
class TestWait:
   def __init__(self,driver):
   	self.d = driver

   def test(self):
        #浏览器在等待5秒内元素出现()
        WebDriverWait(self.d,5).until(ec.visibility_of_element_located(*self.sle))
        #用find_element()方法完成定位 传参定位方式和元素 *self.sle  *
        self.d.find_element(*self.sle)

#coding=UTF-8
from selenium import webdriver
from time import sleep
from time import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
a=str(int(time()))#引用时间

d = webdriver.Firefox()
d.get('https://www.baidu.com')
sleep(3)
ActionChains(d).move_to_element(d.find_element_by_css_selector('[href="http://www.baidu.com/gaoji/preferences.html"]')).perform()
sleep(0.5)
d.find_element_by_css_selector('[class="setpref"]').click()
sleep(0.5)
d.find_element_by_class_name('prefpanelgo').click()
d.find_element_by_css_selector('[class="prefpanelgo"]').click()
sleep(0.5)
print(d.switch_to_alert().text)#获取警告框文字
d.switch_to_alert().accept()#确认警告框
d.find_element_by_css_selector('#kw').send_keys('1400')
d.find_element_by_css_selector('#su').click()
d.find_element_by_link_text('登录').click()
d.switch_to.alert
d.find_element_by_css_selector('#TANGRAM__PSP_10__footerULoginBtn').click()
d.find_element_by_id('TANGRAM__PSP_10__footerULoginBtn').click() sleep(0.5)
d.find_element_by_css_selector('#TANGRAM__PSP_10__userName').send_keys('dasdsa') d.find_element_by_css_selector('#TANGRAM__PSP_10__password').send_keys('12345')
d.find_element_by_css_selector('#TANGRAM__PSP_10__submit').click()
sleep(0.5)
xl1=d.find_element_by_css_selector('#TANGRAM__39__content_select_show')
select(xl1).select_by_index(1)  # 下拉框处理
d.find_element_by_css_selector('#TANGRAM__39__content_select_show span').click()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值