python reptile: interaction elements



Import the webdriver Selenium from from selenium.webdriver Import ActionChains from selenium.webdriver.common.keys Import Keys # keyboard operation Import Time Driver = webdriver.Chrome (r'C: \ the Users \ Auraro \ Desktop / chromedriver.exe ') the try: driver.implicitly_wait (10) driver.get ( 'http://www.jd.com/') # click to clear the INPUT = driver.find_element_by_id ( 'Key') input.send_keys ( 'Besieged') # Find Search by class button Search driver.find_element_by_class_name = ( 'button') search.click () # click the search button the time.sleep (. 3) INPUT2 = driver.find_element_by_id ( 'Key') input2.clear () # clear input frame time.sleep(1) input2.send_keys('墨菲定律') input2.send_keys(Keys.ENTER) time.sleep(10) finally: driver.close()


from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.keys import Keys # 键盘按键操作 import time driver = webdriver.Chrome(r'C:\Users\Auraro\Desktop/chromedriver.exe') try: driver.implicitly_wait(10) driver.get('https://www.runoob.com/try/try.php?filename=jqueryui-api-droppable') time.sleep(5) # 遗弃方法 # driver.switch_to_frame() driver.switch_to.frame('iframeResult') time.sleep(1) action = ActionChains(driver) = driver.find_element_by_id Source ( 'draggable with') # target block ID: the droppables target = driver.find_element_by_id ( 'the droppables') # way: second shift # instantaneously start moving to the target block in block # develop a good action, call a method of performing action.drag_and_drop (Source, target) .perform () the time.sleep (10) the finally: driver.close ()
from the webdriver Selenium Import from selenium.webdriver Import ActionChains from selenium.webdriver.common.keys Import Keys # keyboard key operation Import Time Driver = webdriver.Chrome (r'C: \ the Users \ Auraro \ Desktop / chromedriver.exe ') the try: driver.implicitly_wait (10) driver.get (' https://www.runoob.com/try /try.php?filename=jqueryui-api-droppable ')


the time.sleep (. 5) # New Method driver.switch_to.frame ( 'iframeResult') the time.sleep (. 1) Source = driver.find_element_by_id ( 'draggable with') # target block ID: the droppables target = driver.find_element_by_id ( 'the droppables' ) # find sliding distance Print (source.size) # size Print (source.tag_name) # tag name Print (source.text) # text Print (source.location) # coordinates: x and y axis slide distance # find distance = target .location [ 'X'] - source.location [ 'X'] # hold the slider starting ActionChains (Driver) .click_and_hold (Source) .perform () # way: move a little bit S = 0 the while S <distance: # Target acquisition operation chain # abandoned method # driver.switch_to_frame () # every displacement distance s ActionChains (Driver) .move_by_offset (xoffset = 2, yoffset = 0) .perform () S + = 2 the time.sleep (0.1) # start of release slider ActionChains (Driver) .release (). Perform () Time. SLEEP (10) the finally: driver.close ()
from the webdriver Selenium Import from selenium.webdriver Import ActionChains Import Time Driver = webdriver.Chrome (r'C: \ the Users \ Auraro \ Desktop / chromedriver.exe ') the try: driver.implicitly_wait (10) driver.get ( 'https://www.baidu.com/') driver.execute_script ( '' ' Alert ( "Zhejiang Wanli University, Zhejiang best of college!") ' '' ) Time.sleep(5) finally: driver.close()

  

Guess you like

Origin www.cnblogs.com/Auraro997/p/11128064.html