Python selenium.webdriver.common.keys.Keys.BACKSPACE Examples

The following are 13 code examples of selenium.webdriver.common.keys.Keys.BACKSPACE(). 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: upload.py    From bilibiliupload with MIT License 5 votes vote down vote up
def add_information(driver, link, title_):
        # 点击模板
        driver.find_element_by_xpath(r'//*[@class="normal-title-wrp"]/div/p').click()
        driver.find_element_by_class_name(r'template-list-small-item').click()
        # driver.find_element_by_xpath(
        #     r'//*[@id="app"]/div[3]/div[2]/div[3]/div[1]/div[1]/div/div[2]/div[1]').click()
        # 输入转载来源
        input_o = driver.find_element_by_xpath(
            '//*[@class="upload-v2-container"]/div[2]/div[3]/div[1]/div[4]/div[3]/div/div/input')
        input_o.send_keys(link)
        # 选择分区
        # driver.find_element_by_xpath(r'//*[@id="item"]/div/div[2]/div[3]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div[3]/div').click()
        # driver.find_element_by_xpath(r'//*[@id="item"]/div/div[2]/div[3]/div[2]/div[2]/div[1]/div[2]/div[2]/div[1]/div[3]/div[2]/div[6]').click()
        # 稿件标题
        title = driver.find_element_by_xpath(
            '//*[@class="upload-v2-container"]/div[2]/div[3]/div[1]/div[8]/div[2]/div/div/input')
        title.send_keys(Keys.CONTROL + 'a')
        title.send_keys(Keys.BACKSPACE)
        title.send_keys(title_)
        # js = "var q=document.getElementsByClassName('content-tag-list')[0].scrollIntoView();"
        # driver.execute_script(js)
        # time.sleep(3)
        # 输入相关游戏
        # driver.save_screenshot('bin/err.png')
        # print('截图')
        # text_1 = driver.find_element_by_xpath(
        #     '//*[@id="item"]/div/div[2]/div[3]/div[2]/div[2]/div[1]/div[5]/div/div/div[1]/div[2]/div/div/input')
        # text_1.send_keys('星际争霸2')
        # 简介
        text_2 = driver.find_element_by_xpath(
            '//*[@class="upload-v2-container"]/div[2]/div[3]/div[1]/div[12]/div[2]/div/textarea')
        text_2.send_keys('职业选手直播第一视角录像。这个自动录制上传的小程序开源在Github:'
                         'http://t.cn/RgapTpf(或者在Github搜索ForgQi)交流群:837362626'
                         '\n顺便推广一下自己的网站http://web-form.me/') 
Example #2
Source File: page_objects.py    From poium with Apache License 2.0 5 votes vote down vote up
def backspace(self):
        elem = self.__get_element(self.k, self.v)
        elem.send_keys(Keys.BACKSPACE) 
Example #3
Source File: PyWhatsapp.py    From PyWhatsapp with Apache License 2.0 5 votes vote down vote up
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 #4
Source File: PyWhatsapp.py    From PyWhatsapp with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: Salesforce.py    From CumulusCI with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #6
Source File: Salesforce.py    From CumulusCI with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _force_clear(self, element):
        """Use brute-force to clear an element

        This moves the cursor to the end of the input field and
        then issues a series of backspace keys to delete the data
        in the field.
        """
        value = element.get_attribute("value")
        actions = ActionChains(self.selenium.driver)
        actions.move_to_element(element).click().send_keys(Keys.END)
        for character in value:
            actions.send_keys(Keys.BACKSPACE)
        actions.perform() 
Example #7
Source File: webdriver.py    From seldom with Apache License 2.0 5 votes vote down vote up
def backspace(self):
            self.elem.send_keys(Keys.BACKSPACE) 
Example #8
Source File: elements.py    From gigantum-client with MIT License 5 votes vote down vote up
def add_sensitive_file(self, username, project_title, sensitive_file_path, sensitive_file_destination):
        """Add a sensitive file."""
        logging.info("Adding sensitive file")
        self.driver.get(os.environ['GIGANTUM_HOST'] + f'/projects/{username}/{project_title}/environment')
        self.driver.execute_script("window.scrollBy(0, 600);")
        self.advanced_configuration_button.wait_to_appear().click()
        self.driver.execute_script("window.scrollBy(0, 600);")
        self.add_sensitive_file_manager_upload.find().send_keys(sensitive_file_path)
        self.add_sensitive_file_location.click()
        self.add_sensitive_file_location.find().send_keys(Keys.BACKSPACE)
        self.add_sensitive_file_location.find().send_keys(Keys.BACKSPACE)
        self.add_sensitive_file_location.find().send_keys(sensitive_file_destination)
        self.sensitive_file_save_button.click()
        self.sensitive_file_table.wait_to_appear() 
Example #9
Source File: node.py    From capybara.py with MIT License 5 votes vote down vote up
def set(self, value, clear=None):
        tag_name = self.tag_name
        type_attr = self["type"]

        if tag_name == "input" and type_attr == "radio":
            self.click()
        elif tag_name == "input" and type_attr == "checkbox":
            current = self.native.get_attribute("checked") == "true"

            if current ^ value:
                self.click()
        elif tag_name == "textarea" or tag_name == "input":
            if self.readonly:
                raise ReadOnlyElementError()

            if clear == "backspace":
                # Clear field by sending the correct number of backspace keys.
                backspaces = [Keys.BACKSPACE] * len(self.value)
                self.native.send_keys(*([Keys.END] + backspaces + [value]))
            else:
                # Clear field by JavaScript assignment of the value property.
                self.driver.browser.execute_script("arguments[0].value = ''", self.native)
                self.native.send_keys(value)
        elif self["isContentEditable"]:
            self.native.click()
            script = """
                var range = document.createRange();
                var sel = window.getSelection();
                range.selectNodeContents(arguments[0]);
                sel.removeAllRanges();
                sel.addRange(range);
            """
            self.driver.browser.execute_script(script, self.native)
            self.native.send_keys(value) 
Example #10
Source File: test_input.py    From idom with MIT License 5 votes vote down vote up
def test_input_cast_and_ignore_empty(driver, driver_wait, display):
    # ignore empty since that's an invalid float
    change_occured = Event()

    inp = idom.Input("number", 1, {"id": "inp"}, cast=float, ignore_empty=True)

    @inp.events.on("change")
    async def on_change(event):
        change_occured.set()

    display(inp)

    client_inp = driver.find_element_by_id("inp")
    assert client_inp.get_attribute("value") == "1"

    send_keys(client_inp, Keys.BACKSPACE)
    time.sleep(0.1)  # waiting and deleting again seems to decrease flakiness
    send_keys(client_inp, Keys.BACKSPACE)

    assert change_occured.wait(timeout=3.0)
    assert client_inp.get_attribute("value") == ""
    # change ignored server side
    assert inp.value == 1

    send_keys(client_inp, "2")
    driver_wait.until(lambda drv: inp.value == 2) 
Example #11
Source File: element_tests.py    From nerodia with MIT License 5 votes vote down vote up
def test_performs_key_combinations(self, browser):
        receiver = browser.text_field(id='receiver')
        receiver.send_keys('foo')
        receiver.send_keys(MODIFIER + 'a' + Keys.NULL)
        receiver.send_keys(Keys.BACKSPACE)
        assert receiver.value == ''
        assert len(browser.element(id='output').ps()) == 6 
Example #12
Source File: element_tests.py    From nerodia with MIT License 5 votes vote down vote up
def test_supports_combination_of_strings_and_arrays(self, browser):
        receiver = browser.text_field(id='receiver')
        receiver.send_keys('foo', [MODIFIER, 'a'], Keys.BACKSPACE)
        assert receiver.value == ''
        assert len(browser.element(id='output').ps()) == 6 
Example #13
Source File: test_sequence_viewer.py    From dash-bio with MIT License 4 votes vote down vote up
def test_dbsv003_search(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(user_interactions_layout(
        dash_bio.SequenceViewer(
            id=_COMPONENT_ID,
            sequence=_data
        )
    ))

    user_interactions_callback(
        app,
        dash_duo,
        component_id=_COMPONENT_ID,
        prop_name='subpartSelected'
    )

    output_div = dash_duo.find_element('#interaction-results')

    search_input = dash_duo.find_element('input.inputSearchSeq')
    search_input.click()
    search_input.send_keys('lal')

    dash_duo.wait_for_element('span.stringsSelected')

    assert output_div.get_attribute('innerHTML') == json.dumps([
        {'start': 80, 'end': 82, 'sequence': 'LAL'},
        {'start': 14, 'end': 16, 'sequence': 'LAL'},
        {'start': 11, 'end': 13, 'sequence': 'LAL'}
    ])

    # search for something else

    search_input.click()
    for i in range(len('lal')):
        search_input.send_keys(Keys.BACKSPACE)
    search_input.send_keys('SL')

    WebDriverWait(dash_duo.driver, 1).until(
        lambda _:
        output_div.get_attribute('innerHTML') == json.dumps([
            {"start": 101, "end": 102, "sequence": "SL"},
            {"start": 85, "end": 86, "sequence": "SL"},
            {"start": 76, "end": 77, "sequence": "SL"}
        ])
    )

    highlighted_sections = dash_duo.find_elements('span.stringsSelected')
    assert len(highlighted_sections) == 3
    for section in highlighted_sections:
        assert section.get_attribute('innerHTML') == 'SL'