selenium_other methods

1. Multi-window switching During the
test , multiple windows are often opened. Selenium cannot directly locate the element of the newly opened window, so it is necessary to switch windows. Each window has a value (handle). Baidu answer: Handle is an identifier used to identify objects or items, which can be used to describe forms, files, etc.

#coding=utf-8
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("https://www.hao123.com/")
driver.maximize_window()
driver.find_element_by_link_text("hao123推荐").click()

# 切换到新窗口的句柄。句柄的值为drver.window_handles[1],意思就是已打开窗口中的第二个页面。
driver.switch_to.window(driver.window_handles[1])

driver.find_element_by_link_text('娱乐').click()
time.sleep(3)
driver.quit()

2. Fuzzy positioning

# 定位lable标签下,包含gis的所有元素
driver.find_element_by_xpath('//lable[contains(@type,"gis")]').click()
# 定位纯文本
driver.find_element_by_xpath('//*[text()="新闻"]')
# 定位超链接
driver.find_element_by_link_text("新闻")
# 定位包含“进阶应用”这几个字的超链接
driver.find_elements_by_partial_link_text("进阶应用")

3. Screenshot operation is
temporarily not used, priority is lower
4. Slider operation is
temporarily not used, priority is lower

Guess you like

Origin blog.csdn.net/weixin_45451320/article/details/112547206