#coding=utf-8 from selenium import webdriver import time driver = webdriver.Firefox() driver.get("https://www.baidu.com/") #给搜索输入框标红javascript脚本 js="var q=document.getElementById(\"kw\");q.style.border=\"2px solid red\";" #调用给搜索输入框标红js脚本 driver.execute_script(js) time.sleep(3) #单独执行js脚本 driver.execute_script('alert("输入框标红了!")') time.sleep(3) #接受提示信息 driver.switch_to_alert().accept() time.sleep(3) #js隐藏元素,将获取的图片元素隐藏 img1 = driver.find_element_by_xpath("//*[@id='lg']/img") driver.execute_script('$(arguments[0]).fadeOut()',img1) time.sleep(3) driver.find_element_by_xpath("//*[@id='kw']").send_keys("selenium") driver.find_element_by_xpath("//*[@id='su']").click() time.sleep(3) driver.quit()
原文地址:https://blog.csdn.net/u013372487/article/details/46502853