一、元素定位

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)

元素滚动条

https://blog.csdn.net/egegerhn/article/details/123374599

https://www.cnblogs.com/hls-code/p/15634012.html

js2 = "var q=document.getElementById('specUL').scrollTop=150"
driver.execute_script(js2)

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('')")

 

posted on 2020-07-13 22:23  喻解  阅读(154)  评论(0编辑  收藏  举报