#获取属性: # tag.get_attribute('src') #获取文本内容 # tag.text #获取标签ID,位置,名称,大小(了解) # print(tag.id) # print(tag.location) # print(tag.tag_name) # print(tag.size) #模拟浏览器前进后退 # browser.back() # time.sleep(10) # browser.forward() #cookies管理 # print(browser.get_cookies()) 获取cookie # browser.add_cookie({'k1':'xxx','k2':'yyy'}) 设置cookie # print(browser.get_cookies()) #运行js # from selenium import webdriver # import time # # bro=webdriver.Chrome() # bro.get("http://www.baidu.com") # bro.execute_script('alert("hello world")') #打印警告 # time.sleep(5) #选项卡管理 # import time # from selenium import webdriver # # browser=webdriver.Chrome() # browser.get('https://www.baidu.com') # browser.execute_script('window.open()') # # print(browser.window_handles) #获取所有的选项卡 # browser.switch_to_window(browser.window_handles[1]) # browser.get('https://www.taobao.com') # time.sleep(3) # browser.switch_to_window(browser.window_handles[0]) # browser.get('https://www.sina.com.cn') # browser.close() #动作链 # from selenium import webdriver # from selenium.webdriver import ActionChains # # from selenium.webdriver.support.wait import WebDriverWait # 等待页面加载某些元素 # import time # # driver = webdriver.Chrome() # driver.get('http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable') # wait=WebDriverWait(driver,3) # # driver.implicitly_wait(3) # 使用隐式等待 # # try: # driver.switch_to.frame('iframeResult') ##切换到iframeResult # sourse=driver.find_element_by_id('draggable') # target=driver.find_element_by_id('droppable') # # # #方式一:基于同一个动作链串行执行 # # actions=ActionChains(driver) #拿到动作链对象 # # actions.drag_and_drop(sourse,target) #把动作放到动作链中,准备串行执行 # # actions.perform() # # #方式二:不同的动作链,每次移动的位移都不同 # # # ActionChains(driver).click_and_hold(sourse).perform() # distance=target.location['x']-sourse.location['x'] # # # track=0 # while track < distance: # ActionChains(driver).move_by_offset(xoffset=2,yoffset=0).perform() # track+=2 # # ActionChains(driver).release().perform() # # time.sleep(10) # # # finally: # driver.close()