class AddAToDoText(unittest.TestCase): def setUp(self): options = EdgeOptions() options.use_chromium = True options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe" dir = os.path.dirname(os.path.realpath(__file__)) edge_driver_path = dir + "\\edgedriver_win64\\msedgedriver.exe" self.service = Service(edge_driver_path) self.service.start() self.driver = Edge(options=options, service=self.service) self.driver.implicitly_wait(30) self.driver.maximize_window() self.driver.get("http://*****:*****@class='toggle']/following-sibling::label").get_attribute( "innerText") self.assertEqual("The test is adding this todo", addedToDoText) def tearDown(self): self.driver.quit() self.service.stop()
def update(): print("spider update") service = Service('D:\ProgramData\Anaconda3\Scripts\msedgedriver.exe') service.start() driver = webdriver.Remote(service.service_url) driver.get('http://weather.sina.com.cn') data = driver.find_elements_by_class_name('slider_degree')[0] print(data.text) driver.quit()
class HeaderText(unittest.TestCase): def setUp(self): options = EdgeOptions() options.use_chromium = True options.binary_location = "C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe" dir = os.path.dirname(os.path.realpath(__file__)) edge_driver_path = dir + "\\edgedriver_win64\\msedgedriver.exe" self.service = Service(edge_driver_path) self.service.start() self.driver = Edge(options=options, service=self.service) self.driver.implicitly_wait(30) self.driver.maximize_window() self.driver.get("http://localhost:4200") def test_HeaderText(self): headerText = self.driver.find_element(By.CSS_SELECTOR, "h1").get_attribute("innerText") self.assertEqual("todos", headerText) def tearDown(self): self.driver.quit() self.service.stop()
class WebDriver(RemoteWebDriver): def __init__(self, executable_path='MicrosoftWebDriver.exe', capabilities=None, port=DEFAULT_PORT, verbose=False, service_log_path=None, log_path=DEFAULT_SERVICE_LOG_PATH, service=None, options=None, keep_alive=False): """ Creates a new instance of the chrome driver. Starts the service and then creates new instance of chrome driver. :Args: - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH - capabilities - Dictionary object with non-browser specific capabilities only, such as "proxy" or "loggingPref". - port - port you would like the service to run, if left as 0, a free port will be found. - verbose - whether to set verbose logging in the service - service_log_path - Where to log information from the driver. - keep_alive - Whether to configure EdgeRemoteConnection to use HTTP keep-alive. """ if port != DEFAULT_PORT: warnings.warn( 'port has been deprecated, please pass in a Service object', DeprecationWarning, stacklevel=2) self.port = port if service_log_path != DEFAULT_SERVICE_LOG_PATH: warnings.warn( 'service_log_path has been deprecated, please pass in a Service object', DeprecationWarning, stacklevel=2) if capabilities is not None: warnings.warn( 'capabilities has been deprecated, please pass in a Service object', DeprecationWarning, stacklevel=2) if service_log_path != DEFAULT_SERVICE_LOG_PATH: warnings.warn( 'service_log_path has been deprecated, please pass in a Service object', DeprecationWarning, stacklevel=2) if verbose: warnings.warn( 'verbose has been deprecated, please pass in a Service object', DeprecationWarning, stacklevel=2) if service: self.service = service else: self.service = Service(executable_path, port=self.port, verbose=verbose, log_path=service_log_path) self.service.start() if capabilities is None: capabilities = DesiredCapabilities.EDGE RemoteWebDriver.__init__(self, command_executor=RemoteConnection( self.service.service_url, resolve_ip=False, keep_alive=keep_alive), desired_capabilities=capabilities) self._is_remote = False @property def edge_service(self): warnings.warn( "'edge_service' has been deprecated, please use 'service'", DeprecationWarning, stacklevel=2) return self.service def quit(self): RemoteWebDriver.quit(self) self.service.stop()