def init_browser(headless: Optional[bool] = True) -> Chrome: chrome_options = Options() if headless: chrome_options.add_argument( "--headless") # Opens the browser up in background browser = Chrome(options=chrome_options) # Agree to google cookies browser.get('https://www.google.com/?hl=en') time.sleep(0.2) agree_button = browser.find_element(By.XPATH, '//div[text()="I agree"]') agree_button.click() return browser
def startServer(self): with open('./NodejsWebApp1/server.js', 'r', encoding='utf8') as f: file = f.readlines() file[0] = "port = " + str(self.port) + ";\n" for i in range(len(file)): if "startTimer(" in file[i] and "function" not in file[i]: file[i] = "\t\tstartTimer(" + str(self.timer) + ");\n" break # file[243] = "\t\tstartTimer(" + str(self.timer) +");\n" # TODO with open('./NodejsWebApp1/server.js', 'w', encoding='utf8') as f: f.writelines(file) if "1" in (subprocess.check_output('sc query "mongodb"').decode( 'utf-8').split('\r\n')[3]): ShellExecute(lpVerb='runas', lpFile='cmd.exe', lpParameters='/c ' + "sc start MongoDB") command = 'node ./NodejsWebApp1/server.js' # /NodejsWebApp1 #self.p.communicate(command) self.p = subprocess.Popen(command, shell=True) webbrowser.register('chrome', Chrome('chrome')) webbrowser.open('http://localhost:' + str(self.port) + '/admin') self.setWindowTitle("伺服器已啟動:port=" + str(self.port) + ", 作答時間: " + str(self.timer) + "秒")
def login(): driver = webdriver.Chrome(executable_path=r"C:\Deepak\SeleniumFramework\chromedriver_win32\chromedriver.exe") driver.maximize_window() from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_experimental_option("detach", True) driver = Chrome(chrome_options=chrome_options) yield
def browser_open(url): browser_name = get_config('webbrowser.name') if browser_name.lower() == 'none': return browser = None if browser_name.lower() == 'chrome': browser_path = get_config('webbrowser.path') if not browser_path: return browser = Chrome(browser_path) else: try: browser = webbrowser.get(browser_name or None) except webbrowser.Error: if browser_name: check_call([browser_name, url]) if browser: browser.open(url)
from webbrowser import Chrome from selenium.webdriver import chrome from selenium import webdriver import pytest path='C:\\chromedriver\\chromedriver.exe' driver = Chrome(executable_path=path) driver.get('http://www.thetestingworld.com/testings')
from webbrowser import Chrome from test_recorder.decorator import video driver = Chrome("../Environment/Drivers/chromedriver.exe") @video() def test_selene_demo(self): driver.get("www.google.com")
import webbrowser from webbrowser import Chrome # used to call Chrome class by using .register('name', Class name) #webbrowser.open(r'www.google.com',0) # open url #webbrowser.open_new(r'www.google.com') print webbrowser.register('chrome', Chrome('chrome')) # here we confirm using chrome by using Chrome class #google = webbrowser #google.open(r'www.google.com') '______________________________________________' import urllib # in urllib must use the full address name http://www...... print urllib.urlopen(r'http://www.google.com').read(5) # .read() & .readline() & .readlines() could be used urllib.urlretrieve(r'http://www.google.com','text.html') # copy HTML of the given site to a given name file print urllib.getproxies() # return a proxy if it was given response = urllib.urlopen(r'http://www.google.com') print response.geturl() headers = response.info() print 'DATE :', headers['date'] print urllib.urlopen(r'http://www.wdylike.appspot.com/?q=shit and shot').read() happynumbers = urllib.urlopen(r'http://www.practicepython.org/assets/happynumbers.txt') happylist = happynumbers.read().split() # make a list for the web page openned # or could be 1 line as follow primenumberss = urllib.urlopen(r'http://www.practicepython.org/assets/primenumbers.txt').read().split()
def open_url(self, event): browser = Chrome() browser.open() browser.get(self.model.app.access_url)