本文整理匯總了Python中selenium.webdriver.firefox.options.Options.add方法的典型用法代碼示例。如果您正苦於以下問題:Python Options.add方法的具體用法?Python Options.add怎麽用?Python Options.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類selenium.webdriver.firefox.options.Options
的用法示例。
在下文中一共展示了Options.add方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Sel_session
# 需要導入模塊: from selenium.webdriver.firefox.options import Options [as 別名]
# 或者: from selenium.webdriver.firefox.options.Options import add [as 別名]
class Sel_session(object):
def __init__(self, url='http://www.fsf.org/', driver = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe',**kwargs):
self.url = url
#self.args = args
self.binarypath = FirefoxBinary(driver)
self.opts = Options()
self.timeout = False
if kwargs is not None:
if kwargs.get('headless','') and kwargs['headless']: self.opts.add('--headless')
self.driver = webdriver.Firefox(firefox_binary=self.binarypath, firefox_options=self.opts)
#if true timeout enables the load_cutoff method in go_to
def start(self):
self.driver.get(self.url)
return self.driver
def go_to(self,x, **kwargs):
self.driver.get(x)
if self.timeout:
self.load_cutoff(kwargs.get("timeout", 10))
def go_to_TO(self, x, **kwargs):
self.driver.get(x)
try:
WebDriverWait(self.driver, 10).until(readyCall())
except TypeError as TE:
print("TYPE ERROR")
return
except:
raise(CustomTimeoutException("Timed out"))
def js(self, x):
return self.driver.execute_script(x)
def close(self):
return self.driver.quit()
def is_enabled(self, prod_id):
#checks to see if the element is DISABLED
result = self.js("return 'disabled' in document.getElementById(\'{0}\').attributes".format(prod_id))
if result:
#if disabled is listed among the element's attributes returns False
return False
else:
return True
def w_load(self, T_O = 30):
#waits for page to finish loading
count = 0
while True:
if self.driver.execute_script('return document.readyState') != "complete" and count <= T_O:
count += 1
time.sleep(1)
elif count > T_O:
break #should probably do something else
else:
break
def ready(self):
if self.driver.execute_script('return document.readyState') == "complete":
return True
else:
return False
def load_cutoff(self, timeout = 10):
start = time.time()
while (time.time() - start) <= timeout and self.driver.execute_script('return document.readyState') != "complete":
print("Wait time: {0}".format(time.time() - start))
if (time.time() - start) > timeout and self.driver.execute_script('return document.readyState') != "complete":
raise CustomTimeoutException("Timed out")
def source(self):
return bs(self.driver.page_source,'lxml')
def element_check(self, element):
try:
self.driver.find_element_by_id(element)
except:
return False
else:
return True
def export_cookies(self):
return self.driver.get_cookies()