当前位置: 首页>>代码示例>>Python>>正文


Python By.XPATH属性代码示例

本文整理汇总了Python中selenium.webdriver.common.by.By.XPATH属性的典型用法代码示例。如果您正苦于以下问题:Python By.XPATH属性的具体用法?Python By.XPATH怎么用?Python By.XPATH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在selenium.webdriver.common.by.By的用法示例。


在下文中一共展示了By.XPATH属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index_page

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def index_page(page):
    try:
        print('正在爬取第: %s 页' % page)
        wait.until(
            EC.presence_of_element_located((By.ID, "dt_1")))
        # 判断是否是第1页,如果大于1就输入跳转,否则等待加载完成。
        if page > 1:
            # 确定页数输入框
            input = wait.until(EC.presence_of_element_located(
                (By.XPATH, '//*[@id="PageContgopage"]')))
            input.click()
            input.clear()
            input.send_keys(page)
            submit = wait.until(EC.element_to_be_clickable(
                (By.CSS_SELECTOR, '#PageCont > a.btn_link')))
            submit.click()
            time.sleep(2)
        # 确认成功跳转到输入框中的指定页
        wait.until(EC.text_to_be_present_in_element(
            (By.CSS_SELECTOR, '#PageCont > span.at'), str(page)))
    except Exception:
        return None 
开发者ID:makcyun,项目名称:eastmoney_spider,代码行数:24,代码来源:eastmoney_crawler.py

示例2: crack

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def crack(self):
        true_image = self.get_true_image()
        x_offset = self.analysis(true_image)
        print(x_offset)

        track = self.get_track(x_offset)
        knob_element = WebDriverWait(self.driver, 50).until(
            EC.element_to_be_clickable((By.XPATH, r'/html/body/div[2]/div[2]/div[6]/div/div[1]/div[2]/div[2]')))
        self.move_to_gap(knob_element, track)

        # fn = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result0.png')
        # fn1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result1.png')
        # time.sleep(0.02)
        # screen_shot = self.driver.save_screenshot(fn)
        # time.sleep(2)
        # screen_shot = self.driver.save_screenshot(fn1) 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:18,代码来源:__init__.py

示例3: login

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def login(driver, filename):
        logger.info('准备更新cookie')
        # screen_shot = driver.save_screenshot('bin/1.png')
        WebDriverWait(driver, 10).until(
            ec.presence_of_element_located((By.XPATH, r'//*[@id="login-username"]')))
        username = driver.find_element_by_xpath(r'//*[@id="login-username"]')
        username.send_keys(engine.user_name)
        password = driver.find_element_by_xpath('//*[@id="login-passwd"]')
        password.send_keys(engine.pass_word)
        driver.find_element_by_class_name("btn-login").click()
        # logger.info('第四步')
        # try:
        cracker = slider_cracker(driver)
        cracker.crack()
        # except:
        #     logger.exception('出错')
        time.sleep(5)
        if driver.title == '投稿 - 哔哩哔哩弹幕视频网 - ( ゜- ゜)つロ 乾杯~ - bilibili':
            cookie = driver.get_cookies()
            print(cookie)
            with open(filename, "w") as f:
                json.dump(cookie, f)
            logger.info('更新cookie成功')
        else:
            logger.info('更新cookie失败') 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:27,代码来源:upload.py

示例4: start_captcha

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def start_captcha():
    driver = webdriver.Firefox()
    driver.get("http://reddit.com")
    driver.find_element(By.XPATH, "//*[@id=\"header-bottom-right\"]/span[1]/a").click()
    time.sleep(1)
    driver.find_element(By.ID, "user_reg").send_keys("qwertyuiop091231")
    driver.find_element(By.ID, "passwd_reg").send_keys("THISISMYPASSWORD!!$")
    driver.find_element(By.ID, "passwd2_reg").send_keys("THISISMYPASSWORD!!$")
    driver.find_element(By.ID, "email_reg").send_keys("biggie.smalls123@gmail.com")
    #driver.find_element_by_tag_name("body").send_keys(Keys.COMMAND + Keys.ALT + 'k')
    iframeSwitch = driver.find_element(By.XPATH, "//*[@id=\"register-form\"]/div[6]/div/div/div/iframe")
    driver.switch_to.frame(iframeSwitch)
    driver.find_element(By.ID, "recaptcha-anchor").click()
    # download captcha image
    # 
    # split payload
    # 
    # reverse_search
    # 
    # driver.quit()

# determines if an image keywords matches the target keyword
# uses the synonyms of the image keyword 
开发者ID:ecthros,项目名称:uncaptcha,代码行数:25,代码来源:ris.py

示例5: click_tiles

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def click_tiles(driver, coords):
    orig_srcs, new_srcs = {}, {}
    for (x, y) in coords:
        logging.debug("[*] Going to click {} {}".format(x,y))
        tile1 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//div[@id="rc-imageselect-target"]/table/tbody/tr[{0}]/td[{1}]'.format(x, y))))
        orig_srcs[(x, y)] = driver.find_element(By.XPATH, "//*[@id=\"rc-imageselect-target\"]/table/tbody/tr[{}]/td[{}]/div/div[1]/img".format(x,y)).get_attribute("src")
        new_srcs[(x, y)] = orig_srcs[(x, y)] # to check if image has changed 
        tile1.click()
        wait_between(0.1, 0.5)

    logging.debug("[*] Downloading new inbound image...")
    new_files = {}
    for (x, y) in orig_srcs:
        while new_srcs[(x, y)] == orig_srcs[(x, y)]:
            new_srcs[(x, y)] = driver.find_element(By.XPATH, "//*[@id=\"rc-imageselect-target\"]/table/tbody/tr[{}]/td[{}]/div/div[1]/img".format(x,y)).get_attribute("src")
            time.sleep(0.5)
        urllib.urlretrieve(new_srcs[(x, y)], "captcha.jpeg")
        new_path = TASK_PATH+"/new_output{}{}.jpeg".format(x, y)
        os.system("mv captcha.jpeg "+new_path)
        new_files[(x, y)] = (new_path)
    return new_files 
开发者ID:ecthros,项目名称:uncaptcha,代码行数:23,代码来源:main.py

示例6: open

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def open(self):
        try:
            self.worker.first(By.CSS_SELECTOR, '#TABLE_DATA_fileList')
        except NoSuchElementException:
            self.print_letter_status('Opening table...', '')

            self.worker.get('/mng/action/home.do?mode=ajax')
            # Open Alma configuration
            self.worker.wait_for_and_click(
                By.CSS_SELECTOR, '#ALMA_MENU_TOP_NAV_configuration')
            # text() = "General"
            self.worker.click(By.XPATH, '//*[@href="#CONF_MENU6"]')
            self.worker.click(By.XPATH, '//*[text() = "Customize Letters"]')
            self.worker.wait_for(By.CSS_SELECTOR, '#TABLE_DATA_fileList')

        return self 
开发者ID:scriptotek,项目名称:alma-slipsomat,代码行数:18,代码来源:slipsomat.py

示例7: submit_login

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def submit_login(self, username, password):

        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located((By.NAME, "username")))
        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located((By.NAME, "password")))
        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located(
                (By.XPATH, '//input[@type="submit"]')))

        username_input = self.selenium.find_element_by_name("username")
        username_input.send_keys(username)
        password_input = self.selenium.find_element_by_name("password")
        password_input.send_keys(password)

        self.selenium.find_element_by_xpath('//input[@type="submit"]').click()

        WebDriverWait(self.selenium, self.DEFAULT_WAIT_TIME).until(
            EC.presence_of_element_located(
                (By.XPATH, '//div[@class="jumbotron"]')))
        import time
        time.sleep(2) 
开发者ID:SaturdayNeighborhoodHealthClinic,项目名称:osler,代码行数:24,代码来源:test.py

示例8: send_message

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
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 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:23,代码来源:whatsapp.py

示例9: send_blind_message

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
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 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:20,代码来源:whatsapp.py

示例10: clear_chat

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def clear_chat(self, name):
        self.browser.find_element_by_css_selector("._3FRCZ").send_keys(name+Keys.ENTER)
        menu_xpath = "/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[3]/div/span"
        WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, menu_xpath)))
        menu = self.browser.find_element_by_xpath(menu_xpath)
        menu.click()
        chains = ActionChains(self.browser)
        for i in range(4):
            chains.send_keys(Keys.ARROW_DOWN)
        chains.send_keys(Keys.ENTER)
        chains.perform()
        clear_xpath = '//*[@id="app"]/div/span[2]/div/div/div/div/div/div/div[2]/div[2]'
        WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, clear_xpath)))
        self.browser.find_element_by_xpath(clear_xpath).click()



    # override the timeout 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:22,代码来源:whatsapp.py

示例11: get_profile_pic

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def get_profile_pic(self, name):
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(name+Keys.ENTER)
        try:
            open_profile = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, "/html/body/div[1]/div/div/div[3]/div/header/div[1]/div/img")))
            open_profile.click()
        except:
            print("nothing found")
        try:
            open_pic =  WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, "/html/body/div[1]/div/div/div[1]/div[3]/span/div/span/div/div/div/div[1]/div[1]/div/img")))
            open_pic.click()
        except:
            print("Nothing found")
        try:
            img = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
                    (By.XPATH,'//*[@id="app"]/div/span[2]/div/div/div[2]/div/div/div/div/img')))
        except:
            print("Couldn't find the URL to the image")
        img_src_url = img.get_attribute('src')
        self.browser.get(img_src_url)
        self.browser.save_screenshot(name+"_img.png") 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:25,代码来源:whatsapp.py

示例12: send_anon_message

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def send_anon_message(self, phone, text):
        payload = urlencode({"phone": phone, "text": text, "source": "", "data": ""})
        self.browser.get("https://api.whatsapp.com/send?"+payload)
        try:
            Alert(self.browser).accept()
        except:
            print("No alert Found")
        WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#action-button")))
        send_message = self.browser.find_element_by_css_selector("#action-button")
        send_message.click()
        confirm = WebDriverWait(self.browser, self.timeout+5).until(EC.presence_of_element_located(
                (By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]")))
        confirm.clear()
        confirm.send_keys(text+Keys.ENTER)

    # Check if the message is present in an user chat 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:18,代码来源:whatsapp.py

示例13: submit_permissions

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def submit_permissions(self):
        assert self.is_on_subpage('permissions')

        # TODO: temporary workaround for #206
        script = (
            'document.getElementsByTagName("footer")' +
            '[0].style.display = "none"'
        )
        self.browser.execute_script(script)

        submit_button = self.BY_CLASS('btn-primary')
        next_header = "Project Overview"
        xpath = "//h2[text()='{}' and not(*[2])]".format(next_header)
        proj_overview_wait = (By.XPATH, xpath)
        self.test.click_through(submit_button, proj_overview_wait)
        assert not self.is_on_page() 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:18,代码来源:ProjectAdd.py

示例14: link_is_present

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def link_is_present(driver, delay, selector, index, results_page):
    """
    verify that the link selector is present and print the search 
    details to console. This method is particularly useful for catching
    the last link on the last page of search results
    """
    try:
        WebDriverWait(driver, delay).until(
            EC.presence_of_element_located(
                (By.XPATH, selector)
            )
        )
        print("**************************************************")
        print("\nScraping data for result  {}" \
                "  on results page  {} \n".format(index, results_page))
    except Exception as e:
        print(e)
        if index < 25:
            print("\nWas not able to wait for job_selector to load. Search " \
                    "results may have been exhausted.")
            return True
        else:
            return False
    else:
        return True 
开发者ID:kirkhunter,项目名称:linkedin-jobs-scraper,代码行数:27,代码来源:client.py

示例15: login

# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import XPATH [as 别名]
def login(self):
        # 获取到登录按钮后点击
        login_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/e4g")))
        login_btn.click()
        # 获取使用微信号登录按钮
        change_login_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/cou")))
        change_login_btn.click()
        # 获取输入账号元素并输入
        account = self.wait.until(EC.presence_of_element_located((By.XPATH, '//*[@resource-id="com.tencent.mm:id/cos"]/android.widget.EditText')))
        account.send_keys("xxxxxxxx")
        # 获取密码元素并输入
        password = self.wait.until(EC.presence_of_element_located((By.XPATH,  '//*[@resource-id="com.tencent.mm:id/cot"]/android.widget.EditText')))
        password.send_keys("xxxxxx")
        # 登录
        login = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/cov")))
        login.click()
        # 点击去掉通讯录提示框
        no_btn = self.wait.until(EC.element_to_be_clickable((By.ID, "com.tencent.mm:id/az9")))
        no_btn.click()
        print('登录成功...') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:22,代码来源:wechat_moment.py


注:本文中的selenium.webdriver.common.by.By.XPATH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。