Beispiel #1
0
 def enter_ZipCode(self):
     myAction = ActionChains(self.driver)
     textBox_ZipCode = self.driver.find_element_by_id(self.ID_ZipCode)
     myAction.click_and_hold(textBox_ZipCode)
     myAction.send_keys_to_element(textBox_ZipCode, "16030")
     myAction.perform()
     time.sleep(0.5)
Beispiel #2
0
    def type_and_send(self, message: str, mentions: bool):
        """
        Entered text in chat, and presses the send button
        :param mentions:
        :param message:
        """
        try:
            element = self.driver.find_element_by_id('com.whatsapp:id/entry')

            if mentions:
                # break the message into parts depending on mentions
                parts = re.split(r"(^|\s)(@[A-Za-z0-9]+)", message)

                for p in parts:
                    # then try to press it after each mention string

                    actions = ActionChains(self.driver)
                    actions.send_keys_to_element(element, p)
                    actions.perform()

                    if re.match(r"(@[A-Za-z0-9]+)", p):
                        self.press_mention()
            else:
                element.send_keys(message)

            element = self.driver.find_element_by_id('com.whatsapp:id/send')
            element.click()

            return True
        except Exception:
            return False
def upload(formatted_names, unformatted_names, path):
    email = '*****@*****.**'
    password = '******'
    dimension = '260'

    driver = webdriver.Chrome(executable_path='C://WebDriver/bin/chromedriver')
    # Go to your page url
    driver.get('https://developer.vuforia.com/vui/auth/login')

    #put in credentials to login
    driver.implicitly_wait(10)
    input_email = driver.find_element_by_id('login_email').send_keys(email)
    input_pass = driver.find_element_by_id('login_password').send_keys(
        password)
    button_login = driver.find_element_by_id('login').click()

    #choose project
    driver.implicitly_wait(10)
    button_target = driver.find_element_by_id('targetManager')
    button_target.click()

    # driver.implicitly_wait(10)
    button_project = driver.find_element_by_class_name('ui-table-tbody')
    button_project.click()

    # #loop multiple times for each image file
    for i in range(len(unformatted_names)):
        print(formatted_names[i], unformatted_names[i])
        #find the window for adding targets
        modal_window = driver.find_element_by_xpath(
            "//*[@id='addDeviceTargetUserView']")
        actions = ActionChains(driver)
        actions.click(modal_window).perform()
        time.sleep(4)

        dimension = driver.find_element_by_id('targetDimension')
        actions.send_keys_to_element(dimension, dimension).perform()
        actions.reset_actions()
        time.sleep(2)

        button_upload = driver.find_element_by_id('targetImgFile')
        name = path + '\\' + unformatted_names[i]
        button_upload.send_keys(name)
        time.sleep(4)

        name_action = ActionChains(driver)
        file_name = driver.find_element_by_id('targetName')
        file_name.clear()

        name_action.send_keys_to_element(file_name,
                                         formatted_names[i]).perform()
        name_action.reset_actions()
        time.sleep(3)

        add_action = ActionChains(driver)
        button_add = driver.find_element_by_id('AddDeviceTargetBtn')
        add_action.click(button_add).perform()
        add_action.reset_actions()

        time.sleep(10)
Beispiel #4
0
    def start_requests(self):
        self.browser.get('https://qzone.qq.com/')
        WebDriverWait(self.browser, 600).until(
            EC.presence_of_element_located((By.ID, "login_frame")))
        self.browser.switch_to.frame('login_frame')
        action = ActionChains(self.browser)
        action.click(self.browser.find_element_by_id("switcher_plogin"))
        action.send_keys_to_element(self.browser.find_element_by_id('u'),
                                    '*******')  # 输入账户
        action.send_keys_to_element(self.browser.find_element_by_id('p'),
                                    '*******')  # 输入密码
        action.click(self.browser.find_element_by_id('login_button'))
        action.perform()

        WebDriverWait(self.browser, timeout=600).until(
            EC.presence_of_element_located((By.ID, "aMainPage")))
        self.browser.find_element_by_id('aMainPage').click()

        WebDriverWait(self.browser, timeout=600).until(
            EC.presence_of_element_located((By.ID, "QM_Profile_Mood_A")))
        self.browser.find_element_by_id('QM_Profile_Mood_A').click()

        self.qzonetoken = self.browser.execute_script(
            "return window.g_qzonetoken")
        self.g_tk = self.browser.execute_script(
            "return QZONE.FP.getACSRFToken()")

        url = "https://h5.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?uin=740624616&inCharset=utf-8&outCharset=utf-8&hostUin=740624616&notice=0&sort=0&pos=0&num=40&cgi_host=http%3A%2F%2Ftaotao.qq.com%2Fcgi-bin%2Femotion_cgi_msglist_v6&code_version=1&format=jsonp&need_private_comment=1&g_tk=" + bytes(
            self.g_tk) + "&qzonetoken=" + bytes(self.qzonetoken)

        yield scrapy.Request(url, self.parse)
Beispiel #5
0
    def GetFocus(cls):

        element = cls.__wait()
        element.send_keys(Keys.NULL)
        action = ActionChains(p_env.MOBILE)
        action.send_keys_to_element(element, Keys.NULL)
        action.perform()
        cls.__clearup()
Beispiel #6
0
 def enter_SSN(self):
     myAction = ActionChains(self.driver)
     textBox_SSN = self.driver.find_element_by_id("ssn")
     myAction.click_and_hold(textBox_SSN)
     myAction.send_keys_to_element(textBox_SSN,
                                   "001234567").send_keys(Keys.TAB)
     myAction.perform()
     time.sleep(0.5)
Beispiel #7
0
    def Enter(cls):
        '''     在指定输入框发送回回车键
        @note: key event -> enter
        '''

        element = cls._element()
        action = ActionChains(Web.driver)
        action.send_keys_to_element(element, Keys.ENTER)
        action.perform()
Beispiel #8
0
 def login(self):
     account = self.driver.find_element_by_xpath("//div[@data-propertyname='username']/input")
     pwd = self.driver.find_element_by_xpath("//div[@data-propertyname='password']/input")
     submit = self.driver.find_element_by_xpath("//input[@type='submit']")
     action = ActionChains(self.driver)
     action.send_keys_to_element(account, '15217811087')
     action.send_keys_to_element(pwd, '145632789')
     action.click(submit)
     action.perform()
Beispiel #9
0
    def Enter(cls):
        #p_log.step_info("normal",u"Element [%s]: SendEnter()" % (cls.__name__, ))

        element = cls.__wait()

        action = ActionChains(p_env.BROWSER)
        action.send_keys_to_element(element, Keys.ENTER)
        action.perform()

        cls.__clearup()
Beispiel #10
0
    def Focus(cls):
        """        在指定输入框发送 Null, 用于设置焦点
        @note: key event ->  NULL
        """

        element = cls._element()
        #         element.send_keys(Keys.NULL)
        action = ActionChains(Web.driver)
        action.send_keys_to_element(element, Keys.NULL)
        action.perform()
Beispiel #11
0
    def TypeIn(cls, value):
        '''
        input value without clear existed values
        '''
        if value == "": return

        element = cls.__wait()
        action = ActionChains(p_env.MOBILE)
        action.send_keys_to_element(element, value)
        action.perform()

        cls.__clearup()
Beispiel #12
0
    def GetFocus(cls):
        #p_log.step_info("normal",u"Element [%s]: GetFocus()" % (cls.__name__, ))

        element = cls.__wait()

        element.send_keys(Keys.NULL)

        action = ActionChains(p_env.BROWSER)
        action.send_keys_to_element(element, Keys.NULL)
        action.perform()

        cls.__clearup()
Beispiel #13
0
    def SendKeys(cls, value):
        '''
        @param value: 文本框,输入的文本
        '''
        if value == "":
            return

        element = cls._element()
        element.clear()
        action = ActionChains(Web.driver)
        action.send_keys_to_element(element, value)
        action.perform()
Beispiel #14
0
 def click_Modify_Salary(self):
     myAction = ActionChains(self.driver)
     # myAction.send_keys(Keys.PAGE_DOWN).perform()
     time.sleep(0.5)
     textBox_Enter_New_Salary = self.driver.find_element_by_xpath(
         self.XPath_Enter_New_Salary)
     length = len(textBox_Enter_New_Salary.text)
     myAction.click_and_hold(textBox_Enter_New_Salary)
     myAction.send_keys_to_element(
         textBox_Enter_New_Salary,
         (length * Keys.BACKSPACE)).pause(1).send_keys("50000").send_keys(
             Keys.ENTER)
     myAction.perform()
     time.sleep(5)
Beispiel #15
0
    def TypeIn(cls, value):
        '''
        input value without clear existed values
        '''
        if value == "": return

        #p_log.step_info("normal",u"Element [%s]: TypeIn Value [%s]." % (cls.__name__, value))

        element = cls.__wait()

        action = ActionChains(p_env.BROWSER)
        action.send_keys_to_element(element, value)
        action.perform()

        cls.__clearup()
Beispiel #16
0
def login(driver):
    username = driver.find_element_by_id("fm-login-id")
    password = driver.find_element_by_id("fm-login-password")
    login_btn = driver.find_element_by_xpath("//div[@class='fm-btn']/button")
    action = ActionChains(driver)
    action.send_keys_to_element(username, "18717792412")
    action.send_keys_to_element(password, "Wphmy520")
    action.click(login_btn)
    action.perform()
    action = ActionChains(driver)
    dragger = driver.find_element_by_id("nc_1_n1z")
    if dragger:
        action.move_to_element(dragger)
        action.click_and_hold(dragger).perform()  # 鼠标左键按下不放
        action.move_by_offset(258, 0).perform()
        # time.sleep(1)
        login_btn.click()
Beispiel #17
0
    def test_key_ctrl(self):
        self.driver.get('http://sahitest.com/demo/label.htm')
        action = ActionChains(self.driver)
        input1 = self.driver.find_element(By.CSS_SELECTOR, "[type=textbox]")
        input2 = self.driver.find_element(By.CSS_SELECTOR,
                                          "tbody td:nth-child(2)")

        # action.send_keys_to_element(input1,'test_user33333')
        # action.key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).pause(1)
        # action.key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).pause(1)
        #
        sleep(5)
        input2.click()  # 切换输入框失败
        # action.move_to_element(input2).click()#切换输入框成功
        # action.key_down(Keys.CONTROL).send_keys('v').key_up(Keys.CONTROL).pause(1)
        action.send_keys_to_element(input2, 'testeset')
        action.perform()
        sleep(2)
Beispiel #18
0
    def Set(cls, value):
        if value == "":
            return

        if value == "SET_EMPTY":
            value = ""

        element = cls.__wait()

        if element.tag_name == "android.widget.ListView":
            cls.Select(value)
        else:
            element.clear()
            action = ActionChains(p_env.MOBILE)
            action.send_keys_to_element(element, value)
            action.perform()

            cls.__clearup()
Beispiel #19
0
    def Set(cls, value):
        if value == "":
            return

        if value == "SET_EMPTY":
            value = ""

        #p_log.step_info("normal",u"Element [%s]: Set Value [%s]." % (cls.__name__, value))

        element = cls.__wait()

        if element.tag_name == "select" or element.tag_name == "ul":
            cls.Select(value)
        else:
            element.clear()
            action = ActionChains(p_env.BROWSER)
            action.send_keys_to_element(element, value)
            action.perform()

            cls.__clearup()
Beispiel #20
0
    def test_keys(self):
        """
        ActionChains按键相关内容
        1. 输入内容hi~
        2. 回退一个字符
        3. 追加 tom
        4. 清空
        :return:
        """
        self.driver.get('http://sahitest.com/demo/label.htm')
        self.driver.maximize_window()
        self.driver.implicitly_wait(3)

        username = self.driver.find_element(By.XPATH,'/html/body/label[1]/input')

        action = ActionChains(self.driver)

        action.send_keys_to_element(username,'hi~')
        action.send_keys_to_element(username,Keys.BACKSPACE).pause(1)
        action.send_keys_to_element(username,Keys.BACKSPACE).pause(1)
        action.send_keys('tom').pause(1)
        action.send_keys_to_element(username,Keys.CLEAR).pause(1)

        action.perform()
        sleep(2)
def chains():
    # 需求:在百度搜索大数据

    from selenium.webdriver import ActionChains
    driver.get("https://www.baidu.com")

    # 获取输入框标签和提交标签
    tag1 = driver.find_element_by_id("kw")
    tag2 = driver.find_element_by_id("su")

    # 创建鼠标行为链对象
    ac = ActionChains(driver)

    # 操控鼠标
    ac.move_to_element(tag1)
    ac.send_keys_to_element(tag1, "大数据")

    ac.move_to_element(tag2)
    ac.click()

    # 执行上面一系列操作
    ac.perform()
Beispiel #22
0
option = webdriver.ChromeOptions()
option.add_argument('--headless')
option.add_argument('--no-sandbox')
browser = webdriver.Chrome(options=option)

last_code = None

print('正在登录...')
browser.get("https://acm.sjtu.edu.cn/OnlineJudge")
input_username = browser.find_element(By.NAME, 'username')
input_password = browser.find_element(By.NAME, 'password')
btn_login = browser.find_element(By.NAME, 'action')

actions = ActionChains(browser)
actions.send_keys_to_element(input_username, username)
actions.send_keys_to_element(input_password, password)
actions.click(btn_login)
actions.perform()

print('登录成功!')
logging.info('登录完成')

while True:
    try:
        browser.get('https://acm.sjtu.edu.cn/OnlineJudge/status#')
        while True:
            time.sleep(SLEEP_TIME)
            browser.refresh()
            print('获取最新提交编号......')
            cur_code = browser.find_element(
from selenium import webdriver
from selenium.webdriver import ActionChains
import time

# webdriver.ChromeOptions.binary_location = './bin/chromedriver.exe'

driver = webdriver.Chrome('./bin/chromedriver.exe')
try:
    driver.get('https://www.google.com')

    time.sleep(10)

    search = driver.find_element_by_id('lst-ib')
    # su = driver.find_element_by_id('su')

    action = ActionChains(driver)
    action.send_keys_to_element(search, 'hello world\n').perform()
    time.sleep(5)

finally:
    driver.close()

Beispiel #24
0
from selenium import webdriver
from selenium.webdriver import ActionChains
driver_path = r'D:\chromedriver\chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path)
driver.get('https://www.baidu.com/')
driver.save_screenshot('k1.png')
inputTag = driver.find_element_by_id('kw')
submitTag = driver.find_element_by_id('su')
ac = ActionChains(driver)
ac.send_keys_to_element(inputTag, 'python')
ac.click(submitTag)
ac.perform()
Beispiel #25
0
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.implicitly_wait(10)

driver.get("https://classic.crmpro.com/")
driver.maximize_window()
time.sleep(2)
'''send keys and click using Actions class'''

username_ele = driver.find_element(By.NAME, "username")
password_ele = driver.find_element(By.NAME, "password")
login_ele = driver.find_element(By.XPATH, "//input[@type='submit']")

action = ActionChains(driver)

action.send_keys_to_element(username_ele, 'batchautomation')
action.send_keys_to_element(password_ele, 'test@12345')
action.click(login_ele).perform()

time.sleep(2)
driver.quit()
Beispiel #26
0
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver import ActionChains
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.implicitly_wait(10)
driver.get("https://classic.crmpro.com/index.html")

username = driver.find_element(By.NAME, 'username')
password = driver.find_element(By.NAME, 'password')
loginButton = driver.find_element(By.CLASS_NAME, 'btn.btn-small')

act_chain = ActionChains(driver)
act_chain.send_keys_to_element(username, '*****@*****.**').perform()
act_chain.send_keys_to_element(password, 'test123')
act_chain.click(loginButton).perform()
time.sleep(3)

driver.quit()
Beispiel #27
0
 def SendEnter(cls):
     element = cls.__wait()
     action = ActionChains(p_env.MOBILE)
     action.send_keys_to_element(element, Keys.ENTER)
     action.perform()
     cls.__clearup()
Beispiel #28
0
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.implicitly_wait(10)
driver.get("https://classic.crmpro.com/")
time.sleep(5)
driver.maximize_window()
usernm_ele = driver.find_element(By.NAME, 'username')
pwd_ele = driver.find_element(By.NAME, 'password')
sub_ele = driver.find_element(By.XPATH, "//input[@type='submit']")

act_Chain = ActionChains(driver)
act_Chain.send_keys_to_element(usernm_ele, 'jsncns')
act_Chain.send_keys_to_element(pwd_ele, 'dvgfd')
act_Chain.click(sub_ele).perform()
Beispiel #29
0
class Browser:
    def __init__(self, driver: WebDriver):
        self.driver = driver
        self.wait = WebDriverWait(self.driver, constants.BASE_WAIT)
        self.driver.implicitly_wait(3)
        self.action = ActionChains(self.driver)

    def accept_alert(self):
        try:
            WebDriverWait(self.driver, 3).until(EC.alert_is_present())
            self.driver.switch_to.alert.accept()
        except TimeoutException:
            logger.info("No alert")

    def add_class(self, locator, class_name):
        logger.info("Add [%s] class to element [%s]" % (locator, class_name))
        time.sleep(
            1.5)  # Wait for execute all jquery requests after click on element
        self.driver.execute_script(
            "return document.querySelector('%s').classList.add('%s')" %
            (locator, class_name))

    def close_current_tab(self):
        self.driver.close()

    def close_unused_tabs(self):
        number_of_tabs = len(self.driver.window_handles)
        while number_of_tabs > 1:
            self.switch_tab(number_of_tabs - 1)
            self.close_current_tab()
            number_of_tabs = len(self.driver.window_handles)
        self.switch_tab(0)

    def dismiss_alert(self):
        try:
            WebDriverWait(self.driver, 3).until(EC.alert_is_present())
            self.driver.switch_to.alert.dismiss()
        except TimeoutException:
            logger.info("No alert")

    def delete_all_cookies(self):
        self.driver.delete_all_cookies()

    def delete_cookies_and_refresh_page(self):
        self.driver.delete_all_cookies()
        self.driver.refresh()

    def get_current_url(self):
        return self.driver.current_url

    def get_page_title(self):
        return self.driver.title

    def go_to_first_tab(self):
        if len(self.driver.window_handles) > 1:
            self.close_current_tab()
            self.switch_tab(0)

    def is_alert_present(self):
        try:
            alert = self.driver.switch_to.alert
            logger.info("Alert is present [%s]" % alert)
            return True
        except NoAlertPresentException:
            logger.info("No alert")
            return False

    def open(self, url):
        logger.info("Open page: %s" % url)
        self.driver.get(url)

    def refresh_page(self):
        logger.info("Refresh page")
        self.driver.refresh()
        while self.is_alert_present():
            self.driver.switch_to.alert.dismiss()
            self.driver.refresh()
            time.sleep(.3)

    def scroll_to_top_page(self):
        logger.info("Scroll to top page")
        self.action.send_keys_to_element(
            self.driver.find_element_by_tag_name('body'),
            Keys.CONTROL + Keys.HOME).perform()

    def send_escape(self):
        self.action.send_keys(Keys.ESCAPE).perform()

    def send_enter(self):
        self.action.send_keys(Keys.RETURN).perform()

    def send_key(self, key):
        action = ActionChains(self.driver)
        action.send_keys(key).perform()

    def switch_to_frame(self, locator):
        self.driver.switch_to.frame(self.driver.find_element(*locator))

    def switch_to_default_content(self):
        logger.info("Switch to default content")
        self.driver.switch_to.default_content()

    def switch_tab(self, tab_number):
        logger.info(f"Switch to {tab_number} tab")
        self.driver.switch_to.window(self.driver.window_handles[tab_number])
Beispiel #30
0
# # 右键点击
# action = ActionChains(driver)
# action.context_click(el_logo).perform()
# # 悬停鼠标
# #-------------------
# from selenium import webdriver
# from selenium.webdriver import ActionChains
# import time
# driver = webdriver.Firefox()
# url = "http://www.baidu.com"
# driver.get(url)
# el_sz = driver.find_element_by_link_text("设置")
# action = ActionChains(driver)
# action.move_to_element(el_sz).perform()
# time.sleep(2)
# driver.close()
#
# 鼠标定位输入关键词
from selenium import webdriver
from selenium.webdriver import ActionChains
import time
driver = webdriver.Firefox()
url = "http://www.baidu.com"
driver.get(url)

el_input = driver.find_element_by_id("kw")
action = ActionChains(driver)
action.send_keys_to_element(el_input,"python").perform()

time.sleep(2)
driver.close()