python selenium right click on an href and choose Save link as... on Chrome.
阿新 • • 發佈:2018-11-29
From:https://stackoverflow.com/questions/42781483/right-click-on-an-href-and-choose-save-link-as-in-python-selenium/42783015
原生程式碼:
from selenium import webdriver from selenium.webdriver import ActionChainsimport pyautogui
driver = webdriver.Chrome() driver.get(link) elem = driver.find_element_by_css_selector('a[target="_blank"]') actionChain = ActionChains(driver) actionChain.context_click(elem).perform()pyautogui.typewrite(['down','down','down','down','enter'])
我的程式碼:
def test_bzw_install(self):
__download_arrow = (By.CLASS_NAME, 'glyphicon-arrow-right')
__bluezone_web_build_logo = (By.CLASS_NAME, 'no-text-decoration')
"""1.Download latest build from bzw Build web site(http://10.17.10.130/bzw) to local"""
"""1.1.Open Build web site(http://10.17.10.130/bzw)"""
self.driver = BaseWebDriver().getDriver(Global().browser)
self.build_page = BzwInstall(self.driver)
self.build_page.go_to()
# """1.2(PlanA).Click Master Download Arrow to download-Pass"""
self.ele_visible_short(self.__bluezone_web_build_logo)
elem_download_arrow = self.get_elements(*self.__download_arrow)[0]
actionChain = ActionChains(self.driver)
actionChain.context_click(elem_download_arrow).perform()
pyautogui.typewrite(['down', 'down', 'down', 'down', 'enter'])