selenium 中clear() 无法清除

def audience_page_search_audience_list_by_name(driver, name):
    # utils.clear_text(driver, By.CSS_SELECTOR, _CSS_INPUT_SEARCH_FILE_NAME_AUDIENCE_HOMEPAGE)
    # above method didn't work at 2021-3-15, so update as following
    input_box = utils.find_element(driver, By.CSS_SELECTOR, _CSS_INPUT_SEARCH_FILE_NAME_AUDIENCE_HOMEPAGE)
    # input_box.send_keys(Keys.chord(Keys.CONTROL, 'a'))
    # input_box.send_keys(Keys.DELETE)
    Ratio = utils.find_element(driver, By.CSS_SELECTOR, _CSS_INPUT_SEARCH_FILE_NAME_AUDIENCE_HOMEPAGE)
    ActionChains(driver).double_click(Ratio).perform()
    Ratio.send_keys(Keys.DELETE)
    utils.wait_for_window(2)
    utils.type_text_press_enter(driver, name, By.CSS_SELECTOR, _CSS_INPUT_SEARCH_FILE_NAME_AUDIENCE_HOMEPAGE)
    utils.wait_for_window(3)
    text = utils.find_element(driver, By.CSS_SELECTOR, _CSS_INPUT_SEARCH_FILE_NAME_AUDIENCE_HOMEPAGE).get_attribute(
        "value")
    print("Pls. note now the search file is {}".format(text))

  

上面代码中被注释的代码就是尝试了,却发现不可用的。

最终双击全选删除的方式可用

 

 

 

 

posted @ 2021-03-15 20:03  巴黎爱工作  阅读(493)  评论(0编辑  收藏  举报