from selenium import webdriver from selenium.webdriver.chrome.options import Options import time browers_path = r'C:UsersAdministratorAppDataLocal360ChromeChromeApplication360chrome.exe' chrome_option = Options() chrome_option.binary_location = browers_path browers_driver = webdriver.Chrome(options=chrome_option) ''' 百度搜索输入关键词,点击搜索,在清除关键词 ''' # from selenium.webdriver.support.ui import Select # browers_driver.get("http://www.baidu.com") # inputag = browers_driver.find_element_by_id('kw') # inputag.send_keys('python') # time.sleep(2) # submitag = browers_driver.find_element_by_id('su') # submitag.click() # time.sleep(2) # inputag.clear() ''' 豆瓣点击选择 下次自动登录 frame框架问题,要先进入框架后才能选择 有新老版本调用switch_to.frame的不同 ''' # browers_driver.get("https://www.douban.com") # time.sleep(5) # elementi= browers_driver.find_element_by_xpath("//iframe[@frameborder='0']") # browers_driver.switch_to.frame(elementi) # a = browers_driver.find_element_by_name('remember') # a.click() ''' 下拉框的选择:有下拉框隐藏问题,用js将style的visibility属性值改成"visible" ''' from selenium.webdriver.support.ui import Select browers_driver.get("http://news.sina.com.cn/c/2020-01-08/doc-iihnzahk2833225.shtml") js = 'document.querySelectorAll("select")[0].style.visibility="visible";' browers_driver.execute_script(js) selectbtn = Select(browers_driver.find_element_by_tag_name('select')) selectbtn.select_by_index(2)