Python selenium.webdriver.common.by.By.XPATH Examples

The following are 30 code examples of selenium.webdriver.common.by.By.XPATH(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module selenium.webdriver.common.by.By , or try the search function .
Example #1
Source File: ris.py    From uncaptcha with MIT License 11 votes vote down vote up
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 
Example #2
Source File: eastmoney_crawler.py    From eastmoney_spider with MIT License 8 votes vote down vote up
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 
Example #3
Source File: WebRunner.py    From PyWebRunner with MIT License 7 votes vote down vote up
def wait_for_visible(self, selector='', **kwargs):
        '''
        Wait for an element to be visible.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.visibility_of_element_located((by, selector)),
                       **kwargs) 
Example #4
Source File: main.py    From uncaptcha with MIT License 7 votes vote down vote up
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 
Example #5
Source File: __init__.py    From bilibiliupload with MIT License 7 votes vote down vote up
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) 
Example #6
Source File: test.py    From osler with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #7
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def find_element(self, selector):
        '''
        Finds an element by CSS/XPATH selector.

        Parameters
        ----------
        selector: str
            A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.

        Returns
        -------
        selenium.webdriver.remote.webelement.WebElement or None
            Returns an element or nothing at all

        '''
        elem = None
        try:
            if selector.startswith('/'):
                elem = self.browser.find_element_by_xpath(selector)
            else:
                elem = self.browser.find_element_by_css_selector(selector)
        except NoSuchElementException:
            pass

        return elem 
Example #8
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def find_elements(self, selector):
        '''
        Finds elements by CSS/XPATH selector.

        Parameters
        ----------
        selector: str
            A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.

        Returns
        -------
        list of selenium.webdriver.remote.webelement.WebElement or list
            Returns a list of elements or empty list

        '''
        elems = []
        try:
            if selector.startswith('/'):
                elems = self.browser.find_elements_by_xpath(selector)
            else:
                elems = self.browser.find_elements_by_css_selector(selector)
        except NoSuchElementException:
            pass

        return elems 
Example #9
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def wait_for_presence(self, selector='', **kwargs):
        '''
        Wait for an element to be present. (Does not need to be visible.)

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.presence_of_element_located((by, selector)) or
                       EC.presence_of_elements_located((by, selector)),
                       **kwargs) 
Example #10
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def wait_for_invisible(self, selector='', **kwargs):
        '''
        Wait for an element to be invisible.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.invisibility_of_element_located((by, selector)),
                       **kwargs) 
Example #11
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def wait_for_text(self, selector='', text='', **kwargs):
        '''
        Wait for an element to contain a specific string.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        text: str
            The string to look for. This must be precise.
            (Case, punctuation, UTF characters... etc.)
        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.text_to_be_present_in_element((by, selector),
                                                        text), **kwargs) 
Example #12
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def get_element(self, selector):
        '''
        Gets element by CSS selector.

        Parameters
        ----------
        selector: str
            A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.

        Returns
        -------
        selenium.webdriver.remote.webelement.WebElement
            A selenium element object.

        '''
        elem = self.find_element(selector)
        if elem:
            return WebRunnerElement(elem._parent, elem._id, elem._w3c)
        else:
            raise NoSuchElementException 
Example #13
Source File: upload.py    From bilibiliupload with MIT License 6 votes vote down vote up
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失败') 
Example #14
Source File: client.py    From linkedin-jobs-scraper with MIT License 6 votes vote down vote up
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 
Example #15
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def wait_for_text_in_value(self, selector='', text='', **kwargs):
        '''
        Wait for an element's value to contain a specific string.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        text: str
            The string to look for. This must be precise.
            (Case, punctuation, UTF characters... etc.)
        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.text_to_be_present_in_element_value((by, selector),
                                                              text), **kwargs) 
Example #16
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 6 votes vote down vote up
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 
Example #17
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 6 votes vote down vote up
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 
Example #18
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 6 votes vote down vote up
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") 
Example #19
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 6 votes vote down vote up
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 
Example #20
Source File: slipsomat.py    From alma-slipsomat with MIT License 6 votes vote down vote up
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 
Example #21
Source File: ProjectAdd.py    From cadasta-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
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() 
Example #22
Source File: wechat_moment.py    From learn_python3_spider with MIT License 6 votes vote down vote up
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('登录成功...') 
Example #23
Source File: ProjectAdd.py    From cadasta-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
def submit_details(self):
        assert self.is_on_subpage('details')
        submit_button = self.BY_CLASS('btn-primary')
        next_header = "Assign permissions to members"
        xpath = "//h3[text()='{}']".format(next_header)
        set_perms_wait = (By.XPATH, xpath)
        self.test.click_through(submit_button, set_perms_wait)
        assert self.is_on_subpage('permissions')

    # ---------------------------
    # Permissions subpage methods 
Example #24
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 5 votes vote down vote up
def is_message_present(self, username, message):
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(username+Keys.ENTER)
        search_bar = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located((By.CSS_SELECTOR, "._1i0-u > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1)")))
        search_bar.click()
        message_search = self.browser.find_element_by_css_selector("._1iopp > div:nth-child(1) > label:nth-child(4) > input:nth-child(1)")
        message_search.clear()
        message_search.send_keys(message+Keys.ENTER)
        try:
            WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/div/div/div[2]/div[3]/span/div/div/div[2]/div/div/div/div/div[1]/div/div/div/div[2]/div[1]/span/span/span")))
            return True
        except TimeoutException:
            return False

    # Get all starred messages 
Example #25
Source File: WebRunner.py    From PyWebRunner with MIT License 5 votes vote down vote up
def count(self, selector):
        '''
        Counts the number of elements that match CSS/XPATH selector.

        Parameters
        ----------
        selector: str
            A CSS/XPATH selector to search for. This can be any valid CSS/XPATH selector.

        Returns
        -------
        int: Number of matching elements.

        '''
        return len(self.get_elements(selector)) 
Example #26
Source File: ProjectAdd.py    From cadasta-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
def search_for_place(self, placename):
        """Searches for the specified place name using the
        map search feature."""

        assert self.is_on_subpage('geometry')

        # Click on search button and wait for input box to appear
        search = self.BY_CLASS('leaflet-pelias-control')
        search_input_wait = (By.CLASS_NAME, 'leaflet-pelias-input')
        self.test.click_through(search, search_input_wait)

        # Type in specified placename and wait for results to appear
        ActionChains(self.browser).send_keys(placename).perform()
        first_word = re.split('\W', placename, maxsplit=1)[0]
        search_results_wait = (By.XPATH, (
            "//ul[@class='leaflet-pelias-list' and " +
            "    ./li[1][" +
            "        @class='leaflet-pelias-result' and " +
            "        contains(.//text(), '{}')".format(first_word) +
            "    ]" +
            "]"
        ))
        try:
            WebDriverWait(self.browser, 60).until(
                EC.presence_of_element_located(search_results_wait)
            )
        except TimeoutException:
            self.test.get_screenshot()
            raise

        # Click on first result that appears, then close the search box
        self.BY_CSS('ul.leaflet-pelias-list li').click()
        self.BY_CLASS('leaflet-pelias-close').click() 
Example #27
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 5 votes vote down vote up
def get_status(self, name):
        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:
            group_xpath = "/html/body/div/div/div/div[3]/header/div[1]/div/span/img"
            click_menu = WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, group_xpath)))
            click_menu.click()
        except TimeoutException:
            raise TimeoutError("Your request has been timed out! Try overriding timeout!")
        except NoSuchElementException:
            return "None"
        except Exception:
            return "None"
        try:
            status_css_selector = ".drawer-section-body > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > span:nth-child(1) > span:nth-child(1)"   # This is the css selector for status
            WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
                (By.CSS_SELECTOR, status_css_selector)))
            status = self.browser.find_element_by_css_selector(status_css_selector).text
            # We will try for 100 times to get the status
            for i in range(10):
                if len(status) > 0:
                    return status
                else:
                    time.sleep(1) # we need some delay
            return "None"
        except TimeoutException:
            raise TimeoutError("Your request has been timed out! Try overriding timeout!")
        except NoSuchElementException:
            return "None"
        except Exception:
            return "None"

    # to get the last seen of the person 
Example #28
Source File: test_page_elements_groups.py    From toolium with Apache License 2.0 5 votes vote down vote up
def init_page_elements(self):
        self.columns = Columns(By.XPATH, './/td') 
Example #29
Source File: TestTaskSubmission.py    From INGInious with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_submit(self):
        driver = self.driver

        driver.get(self.base_url + "/course/test/helloworld")
        print("-----------------Trying to find textarea-----------------")
        for i in range(5):
            try:
                if self.is_element_present(By.CSS_SELECTOR, "div.CodeMirror textarea"):
                    break
            except:
                pass
            time.sleep(1)
        else:
            self.fail("time out")
        print("-----------------Calling script-----------------")
        driver.execute_script("""codeEditors[0].setValue('print "Hello World!"')""")
        time.sleep(2)
        self.assertEqual("""print "Hello World!\"""", driver.find_element_by_css_selector('textarea.code-editor').get_attribute('value'))
        print("-----------------Clicking-----------------")
        driver.find_element_by_id("task-submit").click()
        print("-----------------Trying to find task alert-----------------")
        for i in range(5):
            try:
                if self.is_element_present(By.XPATH, "//div[@id='task_alert']/div/p"):
                    break
            except:
                pass
            time.sleep(1)
        else:
            self.fail("time out")
        print("-----------------Done-----------------")
        print(driver.find_element_by_xpath("//div[@id='task_alert']/div").text)
        self.assertEqual("You solved this difficult task!", driver.find_element_by_xpath("//div[@id='task_alert']/div/p").text)
        self.assertEqual("100.0", driver.find_element_by_id("task_grade").text)
        self.assertEqual("Succeeded", driver.find_element_by_id("task_status").text)
        self.assertEqual("1", driver.find_element_by_id("task_tries").text) 
Example #30
Source File: tv.py    From Kairos with GNU General Public License v3.0 5 votes vote down vote up
def wait_until_chart_is_loaded(browser):
    # xpath_loading = "//*[matches(text(),'(loading|compiling|error)','i')]"
    xpath_loading = "//*[matches(text(),'(loading|compiling)','i')]"
    elem_loading = find_elements(browser, xpath_loading, By.XPATH, False, True, DELAY_BREAK_MINI)
    while elem_loading and len(elem_loading) > 0:
        elem_loading = find_elements(browser, xpath_loading, By.XPATH, False, DELAY_BREAK_MINI)