當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。