页面缩放
driver.execute_script("document.body.style.zoom='0.5'") #缩小
driver.execute_script("document.body.style.zoom='1.7'") #放大
忽略监控提示
# 忽略监控提示
chrome_option.add_experimental_option('excludeSwitches', ['enable-automation'])
driver = webdriver.Chrome(options=chrome_option)
移动底部进度条
driver.execute_script("window.scrollBy(1000,0)")
设置属性
driver.execute_script("document.getElementById('name_date').style.width = 300;")
driver.execute_script("document.getElementById('name_date').style.height = 40;")
浏览器弹窗关闭
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.implicitly_wait(30) # 等待元素存在、命令执行完成
driver.get("D:\\Pychram-Workspace\\py17_web\\myH.html") # 打开有alert弹框的HTML页面
driver.find_element_by_id("press_me").click() # 点击触发alert弹框
alert = WebDriverWait(driver,10).until(EC.alert_is_present()) # 等待元素可见
# 点击确定,关闭弹出框
alert.accept()
获取标签的文本内容
td_list = tr_obj.find_elements_by_tag_name('td')
print(td_list[1].get_attribute('textContent'))