一、元素定位
1.find_element_by_id
2.find_element_by_name
3.find_element_by_xpath
4.find_element_by_link_text
5.find_element_by_partial_link_text
6.find_element_by_tag_name
7.find_element_by_class_name
<p>元素
8.find_element_by_css_selector
(1)copy ele.css
find_element_by_css_selector('css')
(2)[类='属性']
find_element_by_css_selector("[class='']")
(3)标签.属性
find_element_by_css_selector("p.content")
二、driver操作
1.窗口滚动条
js="window.scrollBy(0,700)"
driver.execute_script(js)
2.检查句柄
方法一:
for handle in driver.window_handles:
if handle != driver.current_window_handle:
driver.switch_to.window(handle)
方法二:
def swith_handle(self,driver):
driver.switch_to.window(driver.window_handles[-1])
3.移动到下拉框
from selenium.webdriver.common.action_chains import ActionChains
label = driver.find_element_by_partial_link_text("")
ActionChains(driver).move_to_element(label).perform()
4.等待元素出现
from selenium.webdriver.support.wait import WebDriverWait
m = driver.find_element_by_partial_link_text()
menu = WebDriverWait(driver, 15).until(lambda driver: m)
menu.click()
5.新建页面标签
driver.execute_script("window.open('')")