Esempio n. 1
0
def index_page(page):
    """
    抓取索引页
    :param page: 页码
    """
    print('正在抓取第', page, '页')
    try:
        url = 'https://s.taobao.com/search?q=' + quote(KEYWORD)
        print(url)
        browser.get(url)
        if page > 1:
            input = wait.until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, '#mainsrp-pager div.form > input')))
            submit = wait.until(
                EC.element_to_be_clickable(
                    (By.CSS_SELECTOR,
                     '#mainsrp-pager div.form > span.btn.J_Submit')))
            input.clear()
            input.send_keys(page)
            submit.click()
        wait.until(
            EC.text_to_be_present_in_element(
                (By.CSS_SELECTOR, '#mainsrp-pager li.item.active > span'),
                str(page)))
        wait.until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, '.m-itemlist .items .item')))
        get_products()
    except TimeoutError:
        index_page(page)
    def log_in(self, ):
        try:
            # todo: dealing with popup windows
            # cookies popup
            print('\nClosing cookies window ...')
            WebDriverWait(self.driver, 10).until(
                EC.visibility_of_element_located(
                    (By.XPATH, '//div/div/div[2]/button[1]'))).click()
            sleep(1)

        except Exception:
            self.error = True
            print('Unable to close popup window')
        else:
            try:
                with open(self.keys, 'r') as a:
                    keys_dict = json.loads(a.read())
                # Press button to access the login fields
                sleep(1)
                login_button = self.driver.find_element_by_xpath(
                    '//section[2]/div[1]/div/section[2]/a[1]')
                login_button.click()
                sleep(1)

                # todo: switch window
                #  https://sqa.stackexchange.com/questions/13792/how-to-proceed-after-clicking-a-link-to-new-page-in-selenium-in-python
                window_after = self.driver.window_handles[1]
                self.driver.switch_to.window(window_after)
                print('Logging in with username and password ...')

                WebDriverWait(self.driver, 10).until(
                    EC.presence_of_element_located(
                        (By.XPATH, '//*[@id="username"]')))
                user_name_input = self.driver.find_element_by_xpath(
                    '//*[@id="username"]')
                user_name_input.send_keys(keys_dict['username'][1])
                sleep(1)

                WebDriverWait(self.driver, 10).until(
                    EC.presence_of_element_located(
                        (By.XPATH, '//*[@id="password"]')))
                password_input = self.driver.find_element_by_xpath(
                    '//*[@id="password"]')
                password_input.send_keys(keys_dict['password'][1])
                sleep(1)
                a.close()

                # user_name_input.submit()
                self.driver.find_element_by_xpath(
                    '//form/div[3]/button').submit()
                sleep(1)

            except Exception as e:
                print(e)
                self.error = True
Esempio n. 3
0
    def get_number_of_friends_from_user(self, user_id):
        """
        Method finds the text on a profile page "Friends <num>" on side bar of 'Intro' (not always there),
        'Photos' and 'Friends'.
        :param user_id: User profile page
        :return: The number of friends, or 'User Blocked' if we can't see
        """
        self._facebook_login()
        self.driver.get('https://www.facebook.com/' + user_id)
        time.sleep(2)
        self.driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight);")
        try:
            self.driverWait.until(
                EC.presence_of_element_located((By.CLASS_NAME, '_39g5')))
        except TimeoutException:
            print("Loading page took too long - timeout exception.")

        # Get list of spans ('Intro', 'Photos', 'Friends')
        friends_span = self.driver.find_elements_by_xpath(
            "//span[@class='_2iel _5kx5']")
        number_of_friends_span = self.driver.find_elements_by_xpath(
            "//a[@class='_39g5']")  # Get number of friends.
        if len(friends_span) == 0:
            print('Page - No Friends')
            return 'Page - No Friends'
        if len(number_of_friends_span) == 0:
            print('User Blocked')
            return 'User Blocked'
        print(number_of_friends_span[0].text)
        return number_of_friends_span[0].text
Esempio n. 4
0
    def test_touzijjy(self):
        datas = ExcelReader (self.excel).data
        tzusers=ExcelReader(self.user).data
        tzbidds=ExcelReader(self.bidd).data
        for d in datas:
            with self.subTest (data=d):
                driver=webdriver.Chrome()
                driver.get('http://192.168.1.249:9901/hkjf/index.do?method=getIndexPage')
                WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.ID, 'login')))
                for u in tzusers:
                    with self.subTest(tzuser=u):
                        driver.find_element_by_id ('login').send_keys (int(u['user']))
                        time.sleep(1)
                        e1 = driver.find_element_by_xpath (".//*[@id='txt2']")
                        action = ActionChains (driver)
                        action.move_to_element (e1).click ().send_keys ("2971055a690ad019e9fc08a9971080ccfd6a8b588c69acc28383a12d9cfdcb135a60550a4df643b9967c5fab90ce4eb8e3970c2c093fefe299662ac44e868763d281e8708ab625528d55c6a777b2700bcb9daf7e7e0c6805ffd13760d4ac0120d6f43c2dc05fc38fcff485eedd8859d79200ddb7a9a606b8548fa1d8def1dacc").perform ()

                        driver.find_element_by_xpath(".//*[@id='logindiv']/div/div[2]").submit()
                        for b in tzbidds:
                            with self.subTest (tzbidd=b):
                                # address=("http://192.168.1.249:9901/hkjf/investControllerFront.do?method=detail&code=ed791706-92f7-4435-b6f6-aa944ed87f4c")
                                ad1 = "http://192.168.1.249:9901/hkjf/investControllerFront.do?method=detail&code="
                                ad2 = b['bidd_code']
                                add = ad1 + ad2
                                driver.get(add)
                                time.sleep(1)
                                # driver.find_element_by_id ("projectCode").send_keys (d['title'])
                                driver.find_element_by_id("amount").send_keys(int(d['amount']))
                                driver.find_element_by_link_text("立即投资").click()
                                time.sleep(2)
                #sreach_window=driver.current_window_handle
                #driver.find_element_by_xpath(".//*[@id='PDF9hFVQpC']/div[1]/div[3]/input[1]").click()
                                driver.find_element_by_class_name("dialogBtn").click()
Esempio n. 5
0
 def is_not_element_present(self, how, what, timeout=4):
     try:
         WebDriverWait(self.browser, timeout).until(
             EC.presence_of_element_located((how, what)))
     except TimeoutException:
         return True
     return False
    def google_parse(self,index):
        driver = webdriver.Chrome()
        driver.get(self.google_url[index])
        delay = 3  # seconds
        try:
            myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located(
                (By.CLASS_NAME, "section-layout.section-scrollbox.scrollable-y.scrollable-show")))
            print("Page is ready!")
        except TimeoutException:
            print("Loading took too much time!")
        element = driver.find_element_by_class_name("section-layout.section-scrollbox.scrollable-y.scrollable-show")
        print(element)
        last_height =new_height=869
        result=""
        while (True):
            new_height += 869
            driver.execute_script("""arguments[0].scrollTo(arguments[2],arguments[1]);""", element, new_height,
                                  last_height)
            WebDriverWait(driver, 2)
            time.sleep(2)
            if new_height > driver.execute_script("return arguments[0].scrollHeight;", element):
                elements = driver.find_elements_by_class_name("section-review-text")
                break
            last_height = new_height
        for elem in elements:
            if elem.text != "":
                result+=elem.text + "***"

        check=result.split("***")
        #print(len(check))
        return result
Esempio n. 7
0
 def is_disappeared(self, how, what, timeout=4):
     try:
         WebDriverWait(self.browser, timeout, 1, TimeoutException). \
             until_not(EC.presence_of_element_located((how, what)))
     except TimeoutException:
         return False
     return True
Esempio n. 8
0
    def test_bftz():
        driver = webdriver.Chrome()
        driver.get(
            'http://192.168.1.249:9901/hkjf/index.do?method=getIndexPage')
        WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'login')))

        driver.find_element_by_id('login').send_keys('13301307172')
        time.sleep(1)
        e1 = driver.find_element_by_xpath(".//*[@id='txt2']")
        action = ActionChains(driver)
        action.move_to_element(e1).click().send_keys(
            "2971055a690ad019e9fc08a9971080ccfd6a8b588c69acc28383a12d9cfdcb135a60550a4df643b9967c5fab90ce4eb8e3970c2c093fefe299662ac44e868763d281e8708ab625528d55c6a777b2700bcb9daf7e7e0c6805ffd13760d4ac0120d6f43c2dc05fc38fcff485eedd8859d79200ddb7a9a606b8548fa1d8def1dacc"
        ).perform()

        driver.find_element_by_xpath(
            ".//*[@id='logindiv']/div/div[2]").submit()
        time.sleep(1)
        driver.get(
            "http://192.168.1.249:9901/hkjf/investControllerFront.do?method=detail&code=477a34ea-b344-49fa-8dc2-b256b7502079"
        )
        time.sleep(1)
        #
        driver.find_element_by_id("amount").send_keys("100")
        # driver.find_element_by_xpath(".//*[@id='clientInvestForm']/div[4]/a").click()
        driver.find_element_by_link_text("立即投资").click()
        time.sleep(3)
        #sreach_window=driver.current_window_handle
        #driver.find_element_by_xpath(".//*[@id='PDF9hFVQpC']/div[1]/div[3]/input[1]").click()
        driver.find_element_by_class_name("dialogBtn").click()
Esempio n. 9
0
    def test_touziyyy(self):
        datas = ExcelReader(self.excel).data
        tzusers = ExcelReader(self.user).data
        tzbidds = ExcelReader(self.bidd).data
        for d in datas:
            with self.subTest(data=d):
                driver = webdriver.Firefox
                driver.get('http://192.168.1.249:8602/financial/index.html')
                WebDriverWait(driver, 10).until(
                    EC.presence_of_element_located((By.ID, 'loginTmp')))
                for u in tzusers:
                    with self.subTest(tzuser=u):
                        # driver = webdriver.Chrome ()
                        # driver.get ('http://192.168.1.249:9901/hkjf/index.do?method=getIndexPage')
                        # WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.ID, 'login')))
                        driver.find_element_by_id('loginTmp').send_keys(
                            int(u['user']))
                        time.sleep(1)

                        e1 = driver.find_element_by_id("passwdTmp").send_keys(
                            "a12345")
                        # action = ActionChains (driver)
                        # action.move_to_element (e1).click ().send_keys ("2971055a690ad019e9fc08a9971080ccfd6a8b588c69acc28383a12d9cfdcb135a60550a4df643b9967c5fab90ce4eb8e3970c2c093fefe299662ac44e868763d281e8708ab625528d55c6a777b2700bcb9daf7e7e0c6805ffd13760d4ac0120d6f43c2dc05fc38fcff485eedd8859d79200ddb7a9a606b8548fa1d8def1dacc").perform ()

                        driver.find_element_by_id("loginBtn").submit()
                        time.sleep(10)
Esempio n. 10
0
def find_element(by_type, locator, driver):

    delay = 45  # seconds
    try:
        return WebDriverWait(driver, delay).until(
            EC.presence_of_element_located((by_type, locator)))
    except TimeoutException:
        print "Following element is not found " + locator
Esempio n. 11
0
 def public_element_sendKeys(driver, element, inputContent):
     try:
         WebDriverWait(driver, 10,
                       1).until(EC.presence_of_element_located(element))
     except:
         pass
     finally:
         return element.send_keys(inputContent)
Esempio n. 12
0
 def public_element_clear(driver, element):
     try:
         WebDriverWait(driver, 10,
                       1).until(EC.presence_of_element_located(element))
     except:
         pass
     finally:
         return element.clear()
Esempio n. 13
0
 def public_driver_findElement(driver, ByType, value):
     try:
         WebDriverWait(driver, 10, 1).until(
             EC.presence_of_element_located((ByType, value)))
     except:
         pass
     finally:
         return driver.find_element(ByType, value)
Esempio n. 14
0
 def public_element_getAttribute(driver, element, attributeName):
     try:
         WebDriverWait(driver, 10,
                       1).until(EC.presence_of_element_located(element))
     except:
         pass
     finally:
         return element.get_attribute(attributeName)
    def success_message_is_disappeared_after_adding_to_basket(self, timeout=4):
        try:
            WebDriverWait(self.browser, timeout, 1, TimeoutException). \
                until_not(EC.presence_of_element_located(*ProductPageLocators.SUCCESS_MESSAGE))
        except TimeoutException:
            return False

        return True
Esempio n. 16
0
    def is_disappeared(self, how, what, timeout=4):  # будет ждать до тех пор, пока элемент не исчезнет.
        try:
            WebDriverWait(self.browser, timeout, 1, TimeoutException). \
                until_not(EC.presence_of_element_located((how, what)))
        except TimeoutException:
            return False

        return True
Esempio n. 17
0
 def waitClick(self, time, element):
     try:
         print('元素加载, 页面等待中 ...')
         ui.WebDriverWait(self.browser, time).until(
             EC.presence_of_element_located(element))
         self.browser.find_element(*element)
     except Exception as e:
         print('元素异常, 页面已截图 :')
         self.screenshot()
Esempio n. 18
0
 def public_element_findElements(driver, element, ByType, value):
     try:
         WebDriverWait(driver, 10, 1).until(
             EC.presence_of_element_located((ByType, value)))
     except:
         pass
     finally:
         time.sleep(timeSleep)
         return element.find_elements(ByType, value)
 def w8_until_loading(self):
     try:
         delay = 15
         WebDriverWait(self.driver, delay).until(
             EC.presence_of_element_located(
                 (By.CSS_SELECTOR, 'li.list-item')))
         print('Page is ready!')
     except TimeoutException:
         print('Loading took too much time!')
Esempio n. 20
0
def test_wait(driver):
    driver.get("http://ui.yansl.com/#/loading")
    bt = driver.find_element_by_xpath("//span[contains(text(),'指令方式')]")
    bt.click()
    WebDriverWait(driver,5,0.5).until(
        EC.presence_of_element_located((By.XPATH,'//tbody/tr[1]/td[2]/div'))
    )
    bg = driver.find_element_by_xpath("//tbody/tr[1]/td[2]/div")
    print(bg.text)
    sleep(10)
Esempio n. 21
0
    def is_disappeared(self,
                       how,
                       what,
                       timeout=4):  # проверить, что какой-то элемент исчезает
        try:
            WebDriverWait(self.browser, timeout, 1, TimeoutException). \
                until_not(EC.presence_of_element_located((how, what)))
        except TimeoutException:
            return False

        return True
Esempio n. 22
0
 def is_not_element_present(
         self,
         how,
         what,
         timeout=4):  # элемент не появляется в течение заданного времени:
     try:
         WebDriverWait(self.browser, timeout).until(
             EC.presence_of_element_located((how, what)))
     except TimeoutException:
         return True
     return False
Esempio n. 23
0
 def VerifyPresence(self):
     loateFile = WebDriverWait(self.browser, 20).until(
         EC.presence_of_element_located(
             self.Locator_login_buttons["LattestUploadPublicTab"]))
     fileTitle = loateFile.text
     if fileTitle == 'Second Edited Name':
         a = True
     else:
         a = False
     assert (a)
     print("Public File Sharing successful ! \n")
Esempio n. 24
0
 def get_position(self):
     """
     获取验证码位置
     :return: 验证码位置元组
     """
     img = self.wait.until(
         EC.presence_of_element_located(
             (By.CLASS_NAME, 'geetest_canvas_img')))
     time.sleep(2)
     location = img.location
     size = img.size
     top, bottom, left, right = location['y'], location['y'] + size[
         'height'], location['x'], location['x'] + size['width']
     return (top, bottom, left, right)
Esempio n. 25
0
 def _get_liked_pages_div_elements(self, liked_pages_link):
     self.driver.get(liked_pages_link)
     for i in range(0, self._number_of_liked_pages_to_collect /
                    10):  #about 10 pages load per scroll
         time.sleep(1.5)
         self.driver.execute_script(
             "window.scrollTo(0, document.body.scrollHeight);")
         try:
             self.driverWait.until(
                 EC.presence_of_element_located(
                     (By.XPATH, "//img[starts-with(@class,'_359')]")))
         except TimeoutException:
             print("Reached end of page - no more scroll downs.")
             break
     liked_pages_divs = self.driver.find_elements_by_xpath(
         "//div[@class='clearfix _5t4y _5qo4']")
     return liked_pages_divs
Esempio n. 26
0
 def wait(self, delay, locator):
     WebDriverWait(self.browser,
                   delay).until(EC.presence_of_element_located(locator))
    def test_loanreceiptplan2(self):
        connection = pymysql.connect (host='192.168.1.249', port=3307, user='******', password='******',
                                      db='p2p_product_hotcopy',
                                      charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
        fname = DATA_PATH + '/yueyueying.xlsx'
        fname2 = DATA_PATH + '/sanbiao.xlsx'
        bk = xlrd.open_workbook (fname)
        bk2 = xlrd.open_workbook (fname2)
        shxrange = range (bk.nsheets)
        shxrange2 = range (bk2.nsheets)
        try:
            sh = bk.sheet_by_name ("Sheet1")
            sh2 = bk2.sheet_by_name ("Sheet1")
        except:
            print
            "no sheet in %s named Sheet1" % fname
            "no sheet in %s named Sheet1" % fname2
        # 获取第一行第一列数据
        cell_value = sh.cell_value (1, 0)
        cell_value2 = sh2.cell_value (1, 0)
        print (cell_value)
        print (cell_value2)
        # 通过cursor创建游标
        cursor = connection.cursor ()
        # sql = "SELECT code FROM bidd_info where title='%s'",(cell_value)   # 加str确认与%s匹配
        #
        # # 创建sql 语句,并执行
        # # sql = "SELECT code FROM bidd_info ORDER BY id LIMIT 1"
        # cursor.execute (sql)
        cursor.execute ("SELECT code FROM bidd_info where title=%s", (cell_value,))
        # 提交SQL
        connection.commit ()
        t = cursor.fetchall ()
        # a=t['tel']
        biddtitle = t
        biddcode = biddtitle[0]['code']
        # [{'tel': '15912345678'}]
        print (biddtitle)
        print (biddcode)
        datas = ExcelReader (self.excel).data
        tzusers = ExcelReader (self.user).data
        tzbidds = ExcelReader (self.bidd).data
        for d in datas:
            with self.subTest (data=d):
                driver=webdriver.Chrome()
                driver.get('http://192.168.1.249:9901/hkjf/index.do?method=getIndexPage')
                WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.ID, 'login')))
                for u in tzusers:
                    with self.subTest(tzuser=u):
                        # driver = webdriver.Chrome ()
                        # driver.get ('http://192.168.1.249:9901/hkjf/index.do?method=getIndexPage')
                        # WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.ID, 'login')))
                        driver.find_element_by_id ('login').send_keys (int(u['user']))
                        time.sleep(1)
                        e1 = driver.find_element_by_xpath (".//*[@id='txt2']")
                        action = ActionChains (driver)
                        action.move_to_element (e1).click ().send_keys ("2971055a690ad019e9fc08a9971080ccfd6a8b588c69acc28383a12d9cfdcb135a60550a4df643b9967c5fab90ce4eb8e3970c2c093fefe299662ac44e868763d281e8708ab625528d55c6a777b2700bcb9daf7e7e0c6805ffd13760d4ac0120d6f43c2dc05fc38fcff485eedd8859d79200ddb7a9a606b8548fa1d8def1dacc").perform ()

                        driver.find_element_by_xpath(".//*[@id='logindiv']/div/div[2]").submit()
                        for b in tzbidds:
                            with self.subTest (tzbidd=b):
                                # address=("http://192.168.1.249:9901/hkjf/investControllerFront.do?method=detail&code=ed791706-92f7-4435-b6f6-aa944ed87f4c")
                                ad1 = "http://192.168.1.249:9901/hkjf/investControllerFront.do?method=detail&code="
                                # ad2 = b['bidd_code']
                                ad2=biddcode
                                add = ad1 + ad2
                                driver.get(add)
                                time.sleep(1)

                                # driver.find_element_by_id("amount").send_keys(int(d['amount']))

                                    # t = driver.find_element_by_xpath (
                                    #     "html/body/div[2]/div[2]/div[2]/div[2]/div[1]/span").text
                                    # # string转换为float类型
                                    # setlocale (LC_NUMERIC, 'English_US')
                                    # # 剩余可投金额
                                    # t1 = int(atof (t))  # 123456.0
                                    # # t2=float ('%.2f' % t1)
                                    # # t2='{:.2f}'.format(t1)
                                    #
                                    # print (t)
                                    # print (t1)

                                # 根据表格配置金额投资
                                driver.find_element_by_id ("amount").send_keys (int (d['amount']))
                                # 剩余可投金额--全投
                                time.sleep(1)
                                # driver.find_element_by_id ("amount").send_keys(t1)
                                driver.find_element_by_link_text ("立即投资").click ()
                                time.sleep (1)
                                driver.find_element_by_class_name ("dialogBtn").click ()
                                time.sleep(1)
                #input class="dialogBtn" type="button" value="确定"
        driver.get ("http://192.168.1.249:9901/hkjf/loginAdmin.do?method=tologin")
        driver.find_element_by_xpath (".//*[@id='login']").send_keys ("yradmin")
        driver.find_element_by_xpath (".//*[@id='password']").send_keys ("a12345")
        time.sleep (5)
        # 手动输入验证码
        # driver.find_element_by_xpath (".//*[@id='apLogin']/div[1]/ul/li[3]/p[3]/img").send_keys(text)
        driver.find_element_by_id ("button").submit ()
        # driver.find_element_by_name('verifyCode').clear()
        # driver.find_element_by_xpath (".//*[@id='apLogin']/div[1]/ul/li[3]/p[3]/img").send_keys(text)
        # driver.find_element_by_xpath (".//*[@id='button']").click()

        driver.find_element_by_xpath (".//*[@id='left']/div/ul/li[5]/div/span[1]").click ()
        time.sleep (1)
        driver.find_element_by_link_text ("待审核的借款标").click ()
        driver.switch_to_frame ("contentIframe")
        # driver.find_element_by_name ("title").send_keys(biddtitle)
        driver.find_element_by_name ("title").send_keys (cell_value)
        time.sleep(3)
        driver.find_element_by_link_text ("查询").click ()
        time.sleep(1)
        driver.find_element_by_link_text ("审核").click ()
        time.sleep (1)
        driver.find_element_by_id ("content").send_keys ("满标审核通过")
        driver.find_element_by_link_text ("通过").click ()
        time.sleep (2)
        driver.switch_to_default_content ()
        time.sleep (2)
        # 财务管理-放款

        driver.find_element_by_xpath (".//*[@id='left']/div/ul/li[7]/div/span[1]").click ()
        time.sleep (1)
        driver.find_element_by_link_text ("待放款的借款标").click ()
        driver.switch_to_frame ("contentIframe")
        driver.find_element_by_name ("title").send_keys (cell_value)
        driver.find_element_by_link_text ("查询").click ()
        driver.find_element_by_link_text ("放款").click ()
        time.sleep (2)
        # a = driver.find_element_by_xpath ("//html/body/div/div/div/div[2]/iframe")
        driver.find_element_by_xpath ("//html/body/div/div/div/div[3]/input[1]").click ()
        time.sleep (3)
        al1 = driver.switch_to_alert ()
        al1.accept ()
        time.sleep (2)
        # 查看回款计划
        # 通过cursor创建游标
        cursor = connection.cursor ()
        # 创建sql 语句,并执行
        # sql = "SELECT TITLE FROM bidd_info ORDER BY id LIMIT 1"
        # cursor.execute ("SELECT code FROM bidd_info where title=%s", (cell_value,))
        cursor.execute("SELECT loan_code,receipt_atm,receipt_capital_atm,RECEIPT_INTEREST_ATM,receipt_plan_time,receipt_user_name from loan_receipt_plan  where loan_code=%s",(biddcode,))

        # 提交SQL
        connection.commit ()
        t = cursor.fetchall ()
        # a=t['tel']
        # b=a[0]['TITLE']
        print (t)  # [{'tel': '15912345678'}]
Esempio n. 28
0
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.set_window_size(100, 200)
driver.maximize_window()
#调用js
js = "windows.scrollTo(400,400)"
driver.execute_script(js)

#显式等待 单个元素
element = WebDriverWait(driver, 5, 0.5).unitl(
    EC.presence_of_element_located((By.ID, "KW")))
element.send_keys("qweq")

for i in range(10):
    try:
        el = driver.find_element_by_id("kw")
        if el.is_displayed():
            break
    except:
        pass
else:
    print("time out")
#切换表单 嵌套页面
driver.switch_to.frame("xxxx")  #id/name

#退出表单
Esempio n. 29
0
 def is_not_element_present(self, how, what, timeout=4):  # упадет, как только увидит искомый элемент. Не появился: успех, тест зеленый.
     try:
         WebDriverWait(self.browser, timeout).until(EC.presence_of_element_located((how, what)))
     except TimeoutException:
         return True
     return False
Esempio n. 30
0
atagList = []
atagList = wd.find_elements_by_class_name('marker_complex--apart')

for atag in atagList:
    atag_id = atag.get_attribute("id")
    wd.execute_script("(function() { " +
                      "window.open('https://new.land.naver.com/complexes/" +
                      atag_id + "?ms=" + str(latitude) + ',' + str(longitude) +
                      "," + zoom + "&a=APT&b=A1&e=RETAIL&f=70000');" + "})();")
    time.sleep(0.5)

    wd.switch_to.window(wd.window_handles[-1])
    time.sleep(0.5)
    try:
        rec_div = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, '//script[@async="async"]')))
    except:
        print("time out error")
    atagList2 = []
    while len(atagList2) <= 0:
        atagList2 = wd.find_elements_by_class_name('marker_complex--apart')
    temp = None
    for atag2 in atagList2:
        if atag_id == atag2.get_attribute("id"):
            temp = atag2
            break
    button = temp.find_element_by_css_selector('button.complex_data_button')
    wd.execute_script("arguments[0].click();", button)

    time.sleep(0.5)