本文整理汇总了Python中selenium.webdriver.common.by.By类的典型用法代码示例。如果您正苦于以下问题:Python By类的具体用法?Python By怎么用?Python By使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了By类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_elements
def find_elements(self, by=By.ID, value=None):
"""
'Private' method used by the find_elements_by_* methods.
:Usage:
Use the corresponding find_elements_by_* instead of this.
:rtype: list of WebElement
"""
if not By.is_valid(by) or not isinstance(value, str):
raise InvalidSelectorException("Invalid locator values passed in")
if self.w3c:
if by == By.ID:
by = By.CSS_SELECTOR
value = '[id="%s"]' % value
elif by == By.TAG_NAME:
by = By.CSS_SELECTOR
elif by == By.CLASS_NAME:
by = By.CSS_SELECTOR
value = ".%s" % value
elif by == By.NAME:
by = By.CSS_SELECTOR
value = '[name="%s"]' % value
return self.execute(Command.FIND_ELEMENTS,
{'using': by, 'value': value})['value']
示例2: method
def method(self, by=By.ID, value=None):
if By.is_valid(by) and by == By.CLASS_NAME:
by = By.CSS_SELECTOR
value = "." + value
if original.im_self:
return original(by, value)
else:
return original(self, by, value)
示例3: find_elements
def find_elements(self, by=By.ID, value=None):
"""
'Private' method used by the find_elements_by_* methods.
:Usage:
Use the corresponding find_elements_by_* instead of this.
"""
if not By.is_valid(by) or not isinstance(value, str):
raise InvalidSelectorException("Invalid locator values passed in")
return self.execute(Command.FIND_ELEMENTS,
{'using': by, 'value': value})['value']
示例4: test_auto_write_time_for_orange_python_webdriver
def test_auto_write_time_for_orange_python_webdriver(self):
driver = self.driver
driver.get(self.base_url + "/login.php")
driver.find_element_by_name("txtUserName").clear()
driver.find_element_by_name("txtUserName").send_keys(UserName)
driver.find_element_by_name("txtPassword").send_keys(Password)
driver.find_element_by_name("Submit").click()
driver.find_element_by_link_text("Time").click()
driver.find_element_by_link_text("Timesheets").click()
driver.find_element_by_id("btnEdit").click()
row_count=driver.findElement(By.tagName("tr")).size()
print row_count
示例5: find_elements
def find_elements(self, by=By.ID, value=None):
if not By.is_valid(by) or not isinstance(value, str):
raise InvalidSelectorException("Invalid locator values passed in")
if by == By.ID:
by = By.CSS_SELECTOR
value = '[id="%s"]' % value
elif by == By.TAG_NAME:
by = By.CSS_SELECTOR
elif by == By.CLASS_NAME:
by = By.CSS_SELECTOR
value = ".%s" % value
elif by == By.NAME:
by = By.CSS_SELECTOR
value = '[name="%s"]' % value
return self._execute(Command.FIND_CHILD_ELEMENTS,
{"using": by, "value": value})['value']
示例6: find_elements
def find_elements(self, by=By.ID, value=None):
if not By.is_valid(by) or not isinstance(value, str):
raise InvalidSelectorException("Invalid locator values passed in")
return self._execute(Command.FIND_CHILD_ELEMENTS,
{"using": by, "value": value})['value']
示例7: get_param
= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
ghost = webdriver.PhantomJS(executable_path='E:/software/phantomjs-2.1.1-windows/bin/phantomjs.exe')
def get_param( driver, url ):
driver.get(url)
total_txt = driver.find_element_by_id("total").text
#try:
return total_txt
if __name__ == '__main__':
cid = 566921
url_address = "https://iknow.jp/courses/%d"%cid
#total = get_param(ghost,url_address)
# f = open("record.txt","wt+",encoding="UTF-8")
#ofile_name = "record_%d.txt"%cid
#ofile = codecs.open(ofile_name, "w", "utf-8")
voclist = ghost.findElements(By.xpath("//li"))
for i in voclist:
print(i)
#for j in range(0, total):
current_page = ghost.find_element_by_css_selector('.items').text
print("current page:" + current_page)
k = 0
# get_transaction_from_page(ofile, ghost, int(current_page), total)
ghost.close()
#ofile.close()
示例8: get_parent
def get_parent(self):
return self.web_element.find_element(By.xpath('..'))
示例9: get_items
def get_items(self) -> list:
li_list = self.web_element.find_elements(By.xpath('/li'))
return DomElementFactory.create_dom_element_list(li_list)