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()
selenium基础操作回顾
最新推荐文章于 2024-08-09 18:15:34 发布