def find_element(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 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_CHILD_ELEMENT,
{"using": by, "value": value})['value']
python类CLASS_NAME的实例源码
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 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_CHILD_ELEMENTS,
{"using": by, "value": value})['value']
def find_element_by_class_name(self, name):
"""
Finds an element by class name.
:Args:
- name: The class name of the element to find.
:Usage:
driver.find_element_by_class_name('foo')
"""
return self.find_element(by=By.CLASS_NAME, value=name)
def find_element(self, by=By.ID, value=None):
"""
'Private' method used by the find_element_by_* methods.
:Usage:
Use the corresponding find_element_by_* instead of this.
:rtype: 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_ELEMENT,
{'using': by, 'value': value})['value']
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']
event_firing_webdriver.py 文件源码
项目:devsecops-example-helloworld
作者: boozallen
项目源码
文件源码
阅读 21
收藏 0
点赞 0
评论 0
def find_element_by_class_name(self, name):
return self.find_element(by=By.CLASS_NAME, value=name)
event_firing_webdriver.py 文件源码
项目:devsecops-example-helloworld
作者: boozallen
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def find_elements_by_class_name(self, name):
return self.find_elements(by=By.CLASS_NAME, value=name)
event_firing_webdriver.py 文件源码
项目:devsecops-example-helloworld
作者: boozallen
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
def find_element_by_class_name(self, name):
return self.find_element(by=By.CLASS_NAME, value=name)
def get_geetest_button(self):
"""
????????
:return:
"""
button = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'geetest_radar_tip')))
return button
def get_position(self):
"""
???????
:return: ???????
"""
img = self.wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'geetest_canvas_img')))
time.sleep(2)
location = img.location
size = img.size
top, bottom, left, right = location['y'], location['y'] + size['height'], location['x'], location['x'] + size[
'width']
return (top, bottom, left, right)
def get_slider(self):
"""
????
:return: ????
"""
slider = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'geetest_slider_button')))
return slider
def login(self):
"""
??
:return: None
"""
submit = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'login-btn')))
submit.click()
time.sleep(10)
print('????')
def crack(self):
# ???????
self.open()
# ??????
button = self.get_geetest_button()
button.click()
# ???????
image1 = self.get_geetest_image('captcha1.png')
# ??????
slider = self.get_slider()
slider.click()
# ???????????
image2 = self.get_geetest_image('captcha2.png')
# ??????
gap = self.get_gap(image1, image2)
print('????', gap)
# ??????
gap -= BORDER
# ??????
track = self.get_track(gap)
print('????', track)
# ????
self.move_to_gap(slider, track)
success = self.wait.until(
EC.text_to_be_present_in_element((By.CLASS_NAME, 'geetest_success_radar_tip_content'), '????'))
print(success)
# ?????
if not success:
self.crack()
else:
self.login()
def find_element_by_class_name(self, name):
return self.find_element(by=By.CLASS_NAME, value=name)
def find_elements_by_class_name(self, name):
return self.find_elements(by=By.CLASS_NAME, value=name)
def find_element_by_class_name(self, name):
return self.find_element(by=By.CLASS_NAME, value=name)
def find_elements_by_class_name(self, name):
return self.find_elements(by=By.CLASS_NAME, value=name)
def test_zero_price_purchase(browser, base_test_data, logged_in_student, mocker):
"""
Test that a course can be purchased with a 100%-off coupon
"""
mocker.patch('ecommerce.views.enroll_user_on_success')
# Make a 100% off coupon. By setting the price to $0 we can avoid dealing with Cybersource
coupon = CouponFactory.create(
amount=1,
amount_type=Coupon.PERCENT_DISCOUNT,
coupon_type=Coupon.STANDARD,
content_object=base_test_data.program
)
UserCoupon.objects.create(coupon=coupon, user=logged_in_student)
browser.get("/")
# Click the dashboard link on the upper right of the homepage
browser.click_when_loaded(By.CLASS_NAME, "header-dashboard-link")
browser.assert_no_console_errors()
browser.click_when_loaded(By.CLASS_NAME, "enroll-button")
browser.wait_until_loaded(By.CLASS_NAME, "continue-payment")
# Click back then click the enroll now button again to assert back button behavior
browser.driver.back()
browser.click_when_loaded(By.CLASS_NAME, "enroll-button")
browser.assert_no_console_errors()
# Click 'Continue' on the order summary page
browser.click_when_loaded(By.CLASS_NAME, "continue-payment")
browser.assert_no_console_errors()
browser.wait_until_loaded(By.CLASS_NAME, "toast-message")
# Assert that the purchase went through fine but enrolling in edX failed
# Which makes sense since there is no edX for these tests
assert browser.driver.find_element_by_css_selector(".course-status-messages .status-message .message").text == (
"Something went wrong. You paid for this course but are not enrolled. Contact us for help."
)
browser.assert_no_console_errors()