本文整理汇总了Python中selenium.webdriver.support.wait.WebDriverWait.click方法的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait.click方法的具体用法?Python WebDriverWait.click怎么用?Python WebDriverWait.click使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.wait.WebDriverWait
的用法示例。
在下文中一共展示了WebDriverWait.click方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UploadVideoStory
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def UploadVideoStory(file, story):
try:
elements = browser.find_elements_by_xpath("//*[@name='xhpc_message']")
if len(elements) > 0:
elements[0].click()
sleep(2)
input_photo = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.XPATH, "//*[@id='feedx_container']//*[@name='composer_photo[]']"))
)
image_path = os.path.abspath('image.gif')
input_photo.send_keys(image_path)
input_photo = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.XPATH, "//*[@id='feedx_container']//*[@name='composer_photo[]']"))
)
image_path = os.path.abspath(file)
input_photo.send_keys(image_path)
send_button = WebDriverWait(browser, 15).until(
EC.element_to_be_clickable((By.XPATH, "//*[@data-testid='react-composer-post-button']"))
)
send_button.click()
wait_for_video_alert = WebDriverWait(browser, 5).until(
EC.presence_of_element_located((By.XPATH, '//*[@role="dialog"]'))
)
close_button = WebDriverWait(browser, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '.layerCancel'))
)
close_button.click()
except :
traceback.print_exc()
示例2: test
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def test(self):
FilterTermName = "Test Run"
#click the "Manage" tab
try:
element = WebDriverWait(self.selenium,self._TimeOut). \
until(lambda s: self.find_element(*self._locManageTab))
except Exceptions.TimeoutException:
Assert.fail(Exceptions.TimeoutException)
element.click()
#type in a filter term in the input field
try:
element = WebDriverWait(self.selenium, self._TimeOut) . \
until(lambda s: self.find_element(By.CSS_SELECTOR,"#text-filter"))
except Exceptions.TimeoutException:
Assert.fail(Exceptions.TimeoutException)
element.send_keys(FilterTermName)
try:
elements = WebDriverWait(self.selenium, self._TimeOut) . \
until(lambda s: self.find_elements(By.CSS_SELECTOR,'a.suggestion.new'))
except Exceptions.TimeoutException:
Assert.fail(Exceptions.TimeoutException)
for element in elements:
TermName = element.find_element(By.CSS_SELECTOR, "b").text
TermType = element.find_element(By.CSS_SELECTOR, "i").text
if TermName == FilterTermName and TermType == "[description]":
element.click()
示例3: add_Contact_simple
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def add_Contact_simple(self, contact):
self.driver.find_element_by_xpath("//order-details//tabset//div[2]/div/select").click()
element = WebDriverWait(self.driver, 4).until(
EC.visibility_of_element_located((By.XPATH, "//option[contains(text(), '%s')]" % contact))
)
element.click()
self.driver.find_element_by_xpath("//order-details//div//div[1]/div[2]/div/span/button").click()
示例4: deactivate_user
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def deactivate_user(self, userName=None):
#local locator
_locDisabledStatusAction = (By.XPATH, "//button[@class='disabled status-action' and @name='action-deactivate']")
#find the element associated with the given user
user = self.__find_user(userName)
if user is None:
print "the given user is not found.\n"
return False
else:
try:
statusSelectButton = WebDriverWait(self.selenium,self._TimeOut). \
until(lambda s: user.find_element(*self._locStatusSelectButton))
except Exceptions.TimeoutException:
print "the submit button was not found.\n"
#check the current status of the button
status = statusSelectButton.text
if status == 'active':
#the current status is active, so click the button for the deactivation
statusSelectButton.click()
try:
deactivateButton = WebDriverWait(self.selenium,self._TimeOut). \
until(lambda s: user.find_element(*_locDisabledStatusAction))
#deactivateButton.click()
deactivateButton.submit()
except Exceptions.TimeoutException:
print "the submit button was not found.\n"
else:
#the current status is inactive, so no further action is needed
print "the user is already inactive.\n"
return True
示例5: add_Contact_from_contractor
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def add_Contact_from_contractor(self, contact):
self.driver.find_element_by_xpath('//order-details//tabset/div/tab[2]//div[1]/div[2]/select').click()
element = WebDriverWait(self.driver, 4).until(
EC.element_to_be_clickable((By.XPATH, "//div[3]/select/option[contains(text(), '%s')]" % contact))
)
element.click()
self.driver.find_element_by_xpath("//order-details//tabset//tab[2]//div[2]/button[1]").click()
示例6: SendPhotoMessage
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def SendPhotoMessage(photo_url):
try:
chat_button = browser.find_element_by_css_selector('#fbDockChatBuddylistNub .fbNubButton')
if chat_button.is_displayed():
chat_button.click()
chat_list = WebDriverWait(browser, 5).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '.fbChatOrderedList ul li'))
)
chat_list.click()
chat_block = WebDriverWait(browser, 5).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '.fbNubFlyoutFooter div[role="textbox"]'))
)
chat_block.click()
# sleep(1)
# clicked_attachment = browser.find_element_by_css_selector('form[title="加新相片"] div')
# clicked_attachment.click()
# attachment = WebDriverWait(browser, 5).until(
# EC.presence_of_element_located((By.CSS_SELECTOR, 'input[name="attachment[]"]'))
# )
sleep(2)
attachment = browser.find_element_by_xpath('//*[@name="attachment[]"]')
# browser.find_element_by_name('attachment[]').click(
# browser.find_element_by_css_selector('input.hidde)
image_path = os.path.abspath(photo_url)
print image_path
attachment.clear()
attachment.send_keys("G:\\Game\\SoftwareTestingHW_3\\image.gif")
except Exception, e:
traceback.print_exc()
示例7: test_see_group
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def test_see_group(self):
"""
I should be able to log in as the first user.
I should be able to see one group.
When clicking on that group, I should be able to see 1 file for thar group.
"""
welcome_url = '%s%s' % (self.live_server_url, '/welcome')
self.driver.get(welcome_url)
css_selector_email="input#login_user_email"
css_selector_password="input#login_user_password"
css_selector_submit="button#auth_submit"
css_selector_loginname="a#login-name"
def try_to_login(user):
self.bycss(css_selector_email).send_keys(user.email)
self.bycss(css_selector_password).send_keys(user.password)
self.bycss(css_selector_submit).click()
element = WebDriverWait(self.driver, 10).until(lambda x: x.find_element_by_css_selector(css_selector_loginname))
self.assertEqual(element.text, "%s %s" % (user.firstname, user.lastname), "user name didn't match")
try_to_login(User.objects.all().order_by("id")[0]) #try to login as first user.
self.driver.get(self.live_server_url)
a = self.bycss(".jstree-leaf[rel=ensemble][id_item='1']")
ensemble_name=Ensemble.objects.get(pk=1).name
self.assertEqual(a.text, ensemble_name, "ensemble name didn't match")
#now try and click the link:
a2 = a.find_element_by_tag_name("a")
a2.click()
file_elt = WebDriverWait(self.driver, 3).until(lambda x: x.find_element_by_css_selector(".filesview_ftitle>a"))
self.assertEqual(file_elt.text, Source.objects.get(pk=1).title, "source title didn't match")
file_elt.click()
#check for instance that NB.pers.store.o.file[1].title is the same title
pass
示例8: sendmail
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def sendmail(self,recipients_popup="no"):
#self.login()
driver=self.driver
element = WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,"b.nui-ico.fn-bg.ga0")))
element.click()
if recipients_popup=="no":
element = WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,"input.nui-editableAddr-ipt")))
element.send_keys(self.mail_to)
else:
element = WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.CSS_SELECTOR,"input.nui-editableAddr-ipt")))
element.send_keys("d")
#定位悬停的元素,点击填出的收件人
driver.find_element_by_class_name("nui-menu-item-text").click()
#switch zhuti frame
element = WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.XPATH,"//section/header/div[2]/div[1]/div/div/input")))
element.send_keys(self.mail_topic)
#swith to text iframe
xf = driver.find_element_by_xpath('//*[@class="APP-editor-iframe"]')
driver.switch_to_frame(xf)
driver.find_element_by_css_selector("body.nui-scroll").send_keys("test1261_text")
#back to default content and send email
driver.switch_to_default_content()
示例9: get_all_items
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def get_all_items():
#list to store alll scraped data
all_items = list()
#Display - read about pyvirtualdisplay
display = Display(visible=0, size=(1024, 768))
display.start()
#webdriver - read about selenium.webdriver
driver = webdriver.Firefox()
#this is a starting page we are scraping
driver.get("http://www.federalreserve.gov/apps/reportforms/default.aspx")
#Every element on the HTML page can be located using CSS selectors.
#Opening the starting page in Chrome, right click on the drop-down menu, click "Inspect" we see a tag on the right highlighted, we copy it's id - MainContent_ddl_ReportForms
#Knowing the id of dropdown menu, we can locate it with Selenium like this
main_menu = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"#MainContent_ddl_ReportForms")))
#Drop down menu is an HTML table of options which can be verified in Chrome browser (Developer Tools, that pop up when you right click and press "Inspect" on an element)
#Following returns all of the options - rows in that table
form_options = main_menu.find_elements_by_tag_name("option")
#We count them
option_count = len(form_options)
#Next, we loop over all of them - essentially like we scrolling down the drop down menu and clicking on each every form
for form_i in xrange(1,option_count):
#Get web element corresponding to a form
form = form_options[form_i]
#Click as a mouse click-action in browser
form.click()
#Get text, because we need to store the form number
form_id = form.text
#Locate a web element corresponding to the submit button. By CSS selector which we found by inspection in Chrome browser (same logic as above)
submit_button = WebDriverWait(driver,3).until(EC.presence_of_element_located((By.CSS_SELECTOR,"#MainContent_btn_GetForm")))
#Click as a mouse click-action in browser
submit_button.click()
#Prepare data structures to store all the info we want to scrape
a = dict.fromkeys(['Description','OMB','Background','RespondentPanel','Frequency','PublicRelease'])
#We are on a web page after submit-click, following will search for all items of interest. Or for corresponding
#web-elements
for el in a.keys():
try:
item = driver.find_element_by_css_selector("#MainContent_lbl_"+el+"_data")
#Once found it will store them in our dictionary, if not it will proceed to "except" section and do nothing
a[el] = item.text
except:
#case when there is no such field
pass
#we need form number as well
a['FormNumber'] = form_id
#keeping them all in one list, which will have a dictionary per Form Number - and later, a row in your excel file per Form number
all_items.append(a)
#Ok, that part bothers me a little: it looks like I have to refresh "form_options" each time...
#Otherwise I get following exception: selenium.common.exceptions.StaleElementReferenceException: Message: Element not found in the cache - perhaps the page has changed since it was looked up
driver.get("http://www.federalreserve.gov/apps/reportforms/default.aspx")
main_menu = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.CSS_SELECTOR,"#MainContent_ddl_ReportForms")))
form_options = main_menu.find_elements_by_tag_name("option")
driver.close()
display.stop()
return all_items
示例10: delete_user
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def delete_user(self, name=None):
#local locators
_locUser = (By.XPATH, "//h3[attribute::title='"+name+"']/preceding-sibling::div[attribute::class='controls']")
_locDelButton = (By.CSS_SELECTOR, "button")
#[H] move to the user page
self.__move_to_user_page()
#[M] find the user to leave out of the user list
isGivenUserFound = False
try:
user = WebDriverWait(self.selenium,self._TimeOut). \
until(lambda s: self.find_element(*_locUser))
#take a delete action on the element
delButton = WebDriverWait(self.selenium,self._TimeOut). \
until(lambda s: user.find_element(*_locDelButton))
isGivenUserFound = True
except Exceptions.TimeoutException:
print "let us move on..\n"
if isGivenUserFound == True:
#click the button
delButton.click()
#return the outcome in boolean
return isGivenUserFound
示例11: publish
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def publish(link):
driver.get(link)
find_click(".org-module-link[href*=members]")
type(".auto-search-input", username)
l = lambda _driver: _driver.find_element_by_css_selector("a[href*=publicize]")
elm = WebDriverWait(driver, 25).until(l)
elm.click()
示例12: UploadImageStory
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def UploadImageStory(file, story):
try:
elements = browser.find_elements_by_xpath("//*[@name='xhpc_message']")
if len(elements) > 0:
elements[0].click()
sleep(2)
input_photo = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.XPATH, "//*[@id='feedx_container']//*[@name='composer_photo[]']"))
)
image_path = os.path.abspath(file)
input_photo.send_keys(image_path)
input_content = browser.find_element_by_xpath("//*[@id='feedx_container']//*[@role='combobox']")
input_content.send_keys(story)
send_button = WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//*[@data-testid='react-composer-post-button']"))
)
send_button.click()
sleep(2)
story_wrapper = browser.find_elements_by_css_selector('.userContentWrapper')[0]
assert len(story_wrapper.find_elements_by_css_selector('.uiScaledImageContainer')) > 0
actual_story = story_wrapper.find_element_by_css_selector('.userContent p').text
assert story in actual_story
except :
traceback.print_exc()
browser.quit()
示例13: GoTo_Order_Of_Numb
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def GoTo_Order_Of_Numb(self, OrdeNumb):
self.Find_Order_of_Numb(OrdeNumb)
element = WebDriverWait(self.driver, 5).until(
EC.element_to_be_clickable((By.XPATH, "//orders//table/tbody/tr/td[2]/a[1]"))
)
element.click()
return PageOrder(self.driver)
示例14: search
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def search(self, query):
self.ensure_login()
self.driver.switch_to_default_content()
try:
nav_search = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.ID, 'nav-search'))
)
nav_search.click()
self.ensure_frame('suggest')
form = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, 'form'))
)
search_bar = form.find_element_by_tag_name('input')
search_bar.send_keys(query)
show_results = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@class="results"]/descendant::a'))
)
show_results.click()
self.driver.switch_to_default_content()
wrapper = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, 'front'))
)
iframe = wrapper.find_element_by_tag_name('iframe')
self.driver.switch_to_frame(iframe)
songs = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, 'tbody'))
)
first_song = songs.find_element_by_tag_name('tr')
first_song.click()
first_song.send_keys(Keys.RETURN)
except:
print('Can\'t find element...')
print(traceback.format_exc())
示例15: test_partial_publication
# 需要导入模块: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.wait.WebDriverWait import click [as 别名]
def test_partial_publication(self):
self.login_author()
self.selenium.get(self.live_server_url + self.ignored_part.get_absolute_url())
find_element = self.selenium.find_element_by_css_selector
button = WebDriverWait(self.selenium, 20)\
.until(expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, '.readiness')))
readiness = button.get_attribute('data-is-ready')
button.click()
self.wait_element_attribute_change((By.CSS_SELECTOR, '.readiness'), 'data-is-ready', readiness, 20)
self.content = PublishableContent.objects.get(pk=self.content.pk)
self.ignored_part = self.content.load_version().children[1]
self.assertFalse(self.ignored_part.ready_to_publish, 'part should be marked as not ready to publish')
self.selenium.get(self.live_server_url + self.content.get_absolute_url())
self.selenium.get(self.live_server_url + self.ignored_part.get_absolute_url())
button = find_element('.readiness')
self.assertNotEqual(readiness, button.get_attribute('data-is-ready'),
'part should be marked as not ready to publish')
self.selenium.get(self.live_server_url + self.content.get_absolute_url())
self.ask_validation()
self.logout()
self.login_staff()
self.take_reservation()
self.validate()
url = PublishedContent.objects.get(content__pk=self.content.pk).get_absolute_url_online()
self.selenium.get(self.live_server_url + url)
self.assertRaises(WebDriverException, find_element, 'a[href="{}"]'.format(
reverse('tutorial:view-container', kwargs={
'slug': self.content.slug,
'pk': self.content.pk,
'container_slug': self.ignored_part.slug
})))