file_name = "code.png" file_path = os.path.join(pics_path, file_name) self.driver.find_element_by_tag_name('img').screenshot(file_path)
切换窗口
driver.execute_script('window.open()') driver.switch_to.window(self.driver.window_handles[1]) driver.get(self.url) pics_path = self.create_file_path() file_name = "code.png" file_path = os.path.join(pics_path, file_name) driver.find_element_by_tag_name('img').screenshot(file_path) print('下载图片成功') driver.close() driver.switch_to.window(self.driver.window_handles[0])