Python selenium.webdriver.common.keys.Keys.SHIFT Examples
The following are 14
code examples of selenium.webdriver.common.keys.Keys.SHIFT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.webdriver.common.keys.Keys
, or try the search function
.
Example #1
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 6 votes |
def send_blind_message(self, message): try: message = self.emojify(message) send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located( (By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]"))) messages = message.split("\n") for msg in messages: send_msg.send_keys(msg) send_msg.send_keys(Keys.SHIFT+Keys.ENTER) send_msg.send_keys(Keys.ENTER) return True except NoSuchElementException: return "Unable to Locate the element" except Exception as e: print(e) return False # This method will send you the picture
Example #2
Source File: test_speck.py From dash-bio with MIT License | 6 votes |
def test_dbsp002_click_and_drag(dash_duo): app = dash.Dash(__name__) app.layout = html.Div( dash_bio.Speck( id=_COMPONENT_ID, data=_data ) ) dash_duo.start_server(app) dash_duo.wait_for_element('#' + _COMPONENT_ID) speck = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas') ac = ActionChains(dash_duo.driver) ac.move_to_element(speck).key_down(Keys.SHIFT).drag_and_drop_by_offset( speck, -50, 100).key_up(Keys.SHIFT).perform() dash_duo.percy_snapshot('test-speck_click_and_drag')
Example #3
Source File: test_utils.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 6 votes |
def execute_cell(self, cell_or_index=None, in_console=False, expect_error=False): if isinstance(cell_or_index, int): index = cell_or_index elif isinstance(cell_or_index, WebElement): index = self.index(cell_or_index) else: raise TypeError("execute_cell only accepts a WebElement or an int") self._focus_cell(index) if in_console: self.current_cell.send_keys(Keys.CONTROL, Keys.SHIFT, Keys.ENTER) self._wait_for_done(-1, expect_error) else: self.current_cell.send_keys(Keys.CONTROL, Keys.ENTER) self._wait_for_done(index, expect_error)
Example #4
Source File: PyWhatsapp.py From PyWhatsapp with Apache License 2.0 | 5 votes |
def send_message(target): global message, wait, browser try: x_arg = '//span[contains(@title,' + target + ')]' ct = 0 while ct != 10: try: group_title = wait.until(EC.presence_of_element_located((By.XPATH, x_arg))) group_title.click() break except: ct += 1 time.sleep(3) input_box = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]') for ch in message: if ch == "\n": ActionChains(browser).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.BACKSPACE).perform() else: input_box.send_keys(ch) input_box.send_keys(Keys.ENTER) print("Message sent successfuly") time.sleep(1) except NoSuchElementException: return
Example #5
Source File: PyWhatsapp.py From PyWhatsapp with Apache License 2.0 | 5 votes |
def send_unsaved_contact_message(): global message try: time.sleep(7) input_box = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]') for ch in message: if ch == "\n": ActionChains(browser).key_down(Keys.SHIFT).key_down(Keys.ENTER).key_up(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.BACKSPACE).perform() else: input_box.send_keys(ch) input_box.send_keys(Keys.ENTER) print("Message sent successfuly") except NoSuchElementException: print("Failed to send message") return
Example #6
Source File: whatsapp.py From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 | 5 votes |
def send_message(self, name, message): message = self.emojify(message) # this will emojify all the emoji which is present as the text in string search = self.browser.find_element_by_css_selector("._3FRCZ") search.send_keys(name+Keys.ENTER) # we will send the name to the input key box try: send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located( (By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]"))) messages = message.split("\n") for msg in messages: send_msg.send_keys(msg) send_msg.send_keys(Keys.SHIFT+Keys.ENTER) send_msg.send_keys(Keys.ENTER) return True except TimeoutException: raise TimeoutError("Your request has been timed out! Try overriding timeout!") except NoSuchElementException: return False except Exception: return False # This method will count the no of participants for the group name provided
Example #7
Source File: Salesforce.py From CumulusCI with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _clear(self, element): """Clear the field, using any means necessary This is surprisingly hard to do with a generic solution. Some methods work for some components and/or on some browsers but not others. Therefore, several techniques are employed. """ element.clear() self.selenium.driver.execute_script("arguments[0].value = '';", element) # Select all and delete just in case the element didn't get cleared element.send_keys(Keys.HOME + Keys.SHIFT + Keys.END) element.send_keys(Keys.BACKSPACE) if element.get_attribute("value"): # Give the UI a chance to settle down. The sleep appears # necessary. Without it, this keyword sometimes fails to work # properly. With it, I was able to run 700+ tests without a single # failure. time.sleep(0.25) # Even after all that, some elements refuse to be cleared out. # I'm looking at you, currency fields on Firefox. if element.get_attribute("value"): self._force_clear(element)
Example #8
Source File: elements.py From gigantum-client with MIT License | 5 votes |
def ctrl_shift_enter(self, actions): """Useful for executing a code block""" return actions.key_down(Keys.SHIFT).key_down(Keys.CONTROL).send_keys(Keys.ENTER) \ .key_up(Keys.SHIFT).key_up(Keys.CONTROL).perform()
Example #9
Source File: testvideo.py From netflix-proxy with MIT License | 5 votes |
def enablePlayerDiagnostics(self): actions = ActionChains(self.driver) actions.key_down(Keys.CONTROL).key_down(Keys.ALT).key_down(Keys.SHIFT).send_keys('d').perform()
Example #10
Source File: element_tests.py From nerodia with MIT License | 5 votes |
def test_accepts_modifiers(self, browser): try: browser.link().click(Keys.SHIFT) assert len(browser.windows()) == 2 finally: for window in browser.windows(): if not window.is_current: window.close() assert len(browser.windows()) == 1
Example #11
Source File: element.py From nerodia with MIT License | 5 votes |
def click(self, *modifiers): """ Clicks the element, optionally while pressing the given modifier keys. Note that support for holding a modifier key is currently experimental, and may not work at all. :param modifiers: modifier keys to press while clicking :Example: Click an element browser.element(name='new_user_button').click() :Example: Click an element with shift key pressed from selenium.webdriver.common.keys import Keys browser.element(name='new_user_button').click(Keys.SHIFT) :Example: Click an element with several modifier keys pressed from selenium.webdriver.common.keys import Keys browser.element(name='new_user_button').click(Keys.SHIFT, Keys.CONTROL) """ def method(): if modifiers: action = ActionChains(self.driver) for mod in modifiers: action.key_down(mod) action.click(self.el) for mod in modifiers: action.key_up(mod) action.perform() else: self.el.click() self._element_call(method, self.wait_for_enabled) self.browser.after_hooks.run()
Example #12
Source File: formgrade_utils.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _flag(browser): _send_keys_to_body(browser, Keys.SHIFT, Keys.CONTROL, "f") message = browser.find_element_by_id("statusmessage") WebDriverWait(browser, 10).until(lambda browser: message.is_displayed()) WebDriverWait(browser, 10).until(lambda browser: not message.is_displayed()) return browser.execute_script("return $('#statusmessage').text();")
Example #13
Source File: test_environment.py From gigantum-client with MIT License | 4 votes |
def test_packages(driver: selenium.webdriver, *args, **kwargs): """ Test that pip ,conda, and apt packages install successfully. Args: driver """ r = testutils.prep_py3_minimal_base(driver) username, project_title = r.username, r.project_name pip_package_construct = ("construct", "2.9.45") conda_package_requests = ("requests", "2.22.0") apt_package_vim = "vim-tiny" # Install pip, conda, and apt packages env_elts = testutils.EnvironmentElements(driver) env_elts.open_add_packages_modal(username, project_title) env_elts.add_pip_package(pip_package_construct[0], pip_package_construct[1]) env_elts.add_conda_package(conda_package_requests[0], conda_package_requests[1]) env_elts.add_apt_package(apt_package_vim) env_elts.install_queued_packages() # Open JupyterLab and create Jupyter notebook project_control_elts = testutils.ProjectControlElements(driver) project_control_elts.launch_devtool("JupyterLab") project_control_elts.open_devtool_tab("JupyterLab") jupyterlab_elts = testutils.JupyterLabElements(driver) jupyterlab_elts.jupyter_notebook_button.wait_to_appear().click() time.sleep(5) logging.info("Running script to import packages and print package versions") package_script = "import construct\nimport requests\n" \ "print(construct.__version__,requests.__version__)" actions = ActionChains(driver) actions.move_to_element(jupyterlab_elts.code_input.wait_to_appear()) \ .click(jupyterlab_elts.code_input.find()) \ .send_keys(package_script) \ .key_down(Keys.SHIFT).send_keys(Keys.ENTER).key_up(Keys.SHIFT).key_up(Keys.CONTROL) \ .perform() jupyterlab_elts.code_output.wait_to_appear() # Get JupyterLab package versions logging.info("Extracting package versions from JupyterLab") environment_package_versions = [pip_package_construct[1], conda_package_requests[1]] jupyterlab_package_versions = jupyterlab_elts.code_output.find().text.split(" ") logging.info(f"Environment package version {environment_package_versions} \n " f"JupyterLab package version {jupyterlab_package_versions}") assert environment_package_versions == jupyterlab_package_versions,\ "Environment and JupyterLab package versions do not match"
Example #14
Source File: main.py From whatsapp-bot with MIT License | 4 votes |
def send_emoji_message(self, emoji, message): message_field = self.browser.find_element_by_css_selector( self.message_input_selector) message_field.clear() message_field.click() emoji = EmojiAlphabet(emoji) # Since we have only uppercase emoji alphabets # converting the message to uppercase. message = message.upper() for m in message: emoji_generator = { 'A': emoji.A, 'B': emoji.B, 'C': emoji.C, 'D': emoji.D, 'E': emoji.E, 'F': emoji.F, 'G': emoji.G, 'H': emoji.H, 'I': emoji.I, 'J': emoji.J, 'K': emoji.K, 'L': emoji.L, 'M': emoji.M, 'N': emoji.N, 'O': emoji.O, 'P': emoji.P, 'Q': emoji.Q, 'R': emoji.R, 'S': emoji.S, 'T': emoji.T, 'U': emoji.U, 'V': emoji.V, 'W': emoji.W, 'X': emoji.X, 'Y': emoji.Y, 'Z': emoji.Z, ' ': emoji.heart, } emoji_pieces = emoji_generator[m]() for e in emoji_pieces: # Todo # Show percentage of work done/ emojis sent. message_field.send_keys(e) actions = ActionChains(self.browser) actions.key_down( Keys.SHIFT ).send_keys(Keys.ENTER).key_up(Keys.SHIFT).perform() actions.reset_actions() message_field.send_keys(Keys.ENTER)