Example #1
0
 def test_raises_correct_exception_when_trying_to_interact_with_a_closed_browser(
         self, bkwargs, page):
     from nerodia.browser import Browser
     from nerodia.exception import Error
     with pytest.raises(Error) as e:
         b = Browser(**bkwargs)
         b.goto(page.url('definition_lists.html'))
         b.close()
         b.dl(id='experience-list').id
     assert e.value.args[0] == 'browser was closed'
Example #2
0
def basicSearch():
    # Retirado do Site do Nerodia, para teste inicial #
    browser = Browser(browser='chrome')
    browser.goto('google.com')

    search_input = browser.text_field(title='Pesquisar')
    search_input.value = 'nerodia'
    browser.button(value='Pesquisa Google').click()

    browser.close()
Example #3
0
class Login():
    def __init__(self):
        self.browser = {}

    @keyword
    def open_browser(self, name='chrome'):
        self.browser = Browser(browser=name)

    @keyword
    def open_on_sauce(self):
        caps = {
            'platformName': 'Windows 10',
            'plaformVersion': 'latest',
            'browserName': 'chrome'
        }

        username = environ.get('SAUCE_USERNAME', None)
        access_key = environ.get('SAUCE_ACCESS_KEY', None)

        selenium_endpoint = "http://ondemand.saucelabs.com/wd/hub"

        caps['username'] = username
        caps['accesskey'] = access_key
        caps['name'] = 'Robot Nerodia - Login'

        executor = RemoteConnection(selenium_endpoint, resolve_ip=False)
        remote = webdriver.Remote(command_executor=executor,
                                  desired_capabilities=caps)

        self.browser = Browser(browser=remote, desired_capabilities=caps)

    @keyword
    def go_to_login(self):
        self.browser.goto(BASE_TEST_URL + "login")

    @keyword
    def login_as(self, username, password):
        self.browser.input(id='username').send_keys(username)
        self.browser.input(id='password').send_keys(password)
        self.browser.button(class_name='radius').click()

    @keyword
    def is_error_message_visible(self):
        assert self.browser.element(class_name='error').present

    @keyword
    def is_login_successful(self):
        assert self.browser.element(class_name='success').present

    @keyword
    def close_browser(self):
        self.browser.quit()
Example #4
0
def launch_Kraken():

# Example
# - https://www.programcreek.com/python/example/100026/selenium.webdriver.FirefoxProfile
# Firefox profiles
# - 
# Firefox options
# - https://www.selenium.dev/selenium/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.options.html

    from inspect import getsourcefile
    from os.path import abspath

    pathToHere = abspath(getsourcefile(lambda:0))


    ### 1 Create Firefox Profile instance and Options instance 
    ffprofile = webdriver.FirefoxProfile()
    options = webdriver.firefox.options.Options()

    # Set the download location
    ffprofile.set_preference('browser.download.dir', pathToHere)

    # Disable native events ( vs synthesized events)
    # Always set as False to prevent certain problems 
    ffprofile.set_preference('webdriver_enable_native_events', False)

    # Location of Browser executable 
    options.binary_location = "/Applications/Firefox-Dev.app/Contents/MacOS/firefox"

    # Run headless / no interface
    #options.add_argument('--headless')

    # Ignore HTTPs certificate errors 
    options.add_argument('--ignore-certificate-errors')

    driver = webdriver.Firefox(firefox_profile=ffprofile, firefox_options=options)
    driver.implicitly_wait(30)
    #driver.maximize_window()

    ### 2 Create Nerodia session
    browserSession = Browser(driver)

    try:
        # Launch the website 
        browserSession.goto( API_ENDPOINT )

        return browserSession

    except:
        logging.exception("!!! Unable to create Browser Session !!!")
        logging.exception(sys.exec_info())
Example #5
0
def launch_Simple():
# Returns a BROWSER SESSION

    targetBrowser = 'Firefox'

    try:
        browserSession = Browser(browser=targetBrowser)
        browserSession.goto( API_ENDPOINT )

        return browserSession

    except:
        logging.exception("!!! Unable to create Browser Session !!!")
        logging.exception(sys.exec_info())
Example #6
0
def run():
    br = Browser(browser='chrome')

    br.goto("https://watir.com")

    # Check that "Titus" is somewhere in the page text
    assert "Watir" in br.text

    # Check "open source" is in the intro
    intro_text = br.div(class_name='intro').text
    assert "open source" in intro_text

    # Check that the page is correct via the URL
    br.link(text='Guides').click()
    assert 'watir.com/guides/' in br.url

    br.close()
def browser(request):
    caps = {
        "browserName": "Chrome",
        "sauce:options": {
            "browserName": "Chrome",
            "platformName": "Windows 10",
            "browserVersion": "latest"
        }
    }

    username = os.environ['SAUCE_USERNAME']
    access_key = os.environ['SAUCE_ACCESS_KEY']

    remote_url = 'https://{}:{}@ondemand.saucelabs.com/wd/hub/'.format(username, access_key)

    remote = webdriver.Remote(command_executor=remote_url, desired_capabilities=caps)
    driver = Browser(browser=remote, desired_capabilities=caps)
    driver.goto(TEST_APP_URL)
    yield driver

    driver.quit()
def main(site):
    "Get all redirect links to a series (still have to extract manually  fromAndTo is an good option for this)"
    base = 'https://s.to'
    if base in site:
        site = site.replace(base, "")
    if not site[-1] == "/":
        site = site + "/"
    #print(base)
    #print(site)

    browser = Browser(browser='firefox')
    browser.goto(base + site)
    html = browser.html

    matches = re.findall(
        '<a (?:class="active" )?href="(' + site +
        r'staffel-\d+)" title="Staffel \d+">\d+</a>', html)
    #print(matches)
    episodeRegex = re.compile(
        r'<a href="(' + site +
        r'staffel-\d+/episode-\d+)" data-episode-id="\d*" title="Staffel \d+ Episode \d+" data-season-id="\d+">\d+</a>'
    )
    allepisodes = list()
    for m in matches:
        browser.goto(base + m)
        html = browser.html
        episodes = episodeRegex.findall(html)
        allepisodes.extend(episodes)
    #print(allepisodes)

    VivoRegex = re.compile(
        r'<aclass="watchEpisode"itemprop="url"href="(/redirect/\d*)"target="_blank">\n<iclass="iconVivo"title="HosterVivo"></i>\n<h4>Vivo</h4>\n<divclass="hosterSiteVideoButton">Videoöffnen</div>'
    )

    vivolinks = list()

    for e in allepisodes:
        browser.goto(base + e)
        html = browser.html
        html = html.replace(" ", "")
        vivolink = VivoRegex.findall(html)
        vivolinks.append(vivolink[0])
    #print(vivolinks)
    for vl in vivolinks:
        print(base + vl)
    browser.close()
Example #9
0
from nerodia.browser import Browser

browser = Browser(browser='firefox')
browser.goto('https://my.bplaced.net/')

usrn = browser.text_field(name="credentials_user")
usrn.value = ''
pswd = browser.text_field(name="credentials_pass")
pswd.value = ''
browser.button(value='Login').click()
Example #10
0
"""Basic script showing how Nerodia works."""
from nerodia.browser import Browser

br = Browser(browser='firefox')

br.goto("https://watir.com")

# Check that "Titus" is somewhere in the page text
assert "Watir" in br.text

# Check "open source" is in the intro
intro_text = br.div(class_name='intro').text
assert "open source" in intro_text

# Check that the page is correct via the URL
br.link(text='Guides').click()
assert 'watir.com/guides/' in br.url

br.close()
Example #11
0
def main():

    global browserTwitter, browserNewEgg, username, password, driver, options, rtxCardLink

    options.add_argument("--log-level=3")

    time.sleep(2)

    print("...")

    time.sleep(3)

    #start up text
    clear_console(5)
    print("Welcome to the RTX Bot Script!")
    clear_console(1)
    print("To begin, enter your username and password")
    print("to access your personal information")
    clear_console(5)

    #logs user in to retrieve personal information
    login()

    time.sleep(2)

    print("...")

    time.sleep(3)

    print("User successfully logged in!")

    #loads personal infrormation using password as key for decryption
    loadPersonalInformation()

    time.sleep(2)
    print("...")
    time.sleep(1)
    print("Personal Information Loaded!")

    time.sleep(2)

    print("...")

    time.sleep(3)

    print("Loading vpn...")
    '''
    vpnStart()

    time.sleep(12)
    '''

    print("Connected to VPN!")

    print("...")

    time.sleep(3)

    print("Loading browser to newegg...")

    time.sleep(2)

    driver = webdriver.Chrome(options=options)
    browserNewEgg = Browser(browser=driver)

    time.sleep(4)

    browserNewEgg.goto(rtxCardLink)

    wait(1)

    #clears browser cache
    browserNewEgg.cookies.clear()

    wait(9)

    #closes pop up
    if (browserNewEgg.link(id='popup-close').exists):
        browserNewEgg.link(id='popup-close').click()

    print("All set! Refreshing newegg until they restock")

    x = datetime.datetime.now()
    y = x + datetime.timedelta(seconds=120)

    #checks newegg until restock
    restocked = False
    count = 0
    while restocked == False:

        if (count > 40):
            count = 0

            time.sleep(1)

            print("Restarting browser with new IP...")

            #clears browser cache
            browserNewEgg.cookies.clear()

            time.sleep(1)

            #closes browser
            browserNewEgg.close()

            time.sleep(1)

            #disconnect from vpn
            vpnEnd()

            time.sleep(10)

            #reconnects to vpn
            vpnStart()

            time.sleep(12)

            driver = webdriver.Chrome(options=options)
            browserNewEgg = Browser(browser=driver)
            time.sleep(1)
            browserNewEgg.goto(rtxCardLink)

            time.sleep(12)

            #closes pop up
            if (browserNewEgg.link(id='popup-close').exists):
                browserNewEgg.link(id='popup-close').click()

            wait(2)

        else:
            pass

        browserNewEgg.refresh()
        wait(3)

        locator = {"class": "nav-col", "index": 1}
        condition = (browserNewEgg.div(class_name="product-buy").div().div(
            **locator).button()).exists

        x = datetime.datetime.now()
        condition = x > y

        if (condition):
            restocked = True
        else:
            pass

        count += 1

    clear_console(100)

    print("Cards restocked!")

    time.sleep(1)

    #clicks add to cart
    browserNewEgg.div(class_name="product-buy").div().div(
        **locator).button().click()

    time.sleep(2)

    #declines warrenty if it is presented
    if (not (browserNewEgg.div(class_name="item-summary").exists)):
        locator = {"index": 0}
        browserNewEgg.div(class_name="modal-footer").button(**locator).click()

    time.sleep(2)

    #clicks view cart and checkout
    browserNewEgg.button(title="View Cart & Checkout").click()

    wait(5)

    #says no to masks if asked
    if (browserNewEgg.button(id="Masks_addtocart").exists):
        locator = {"index": 0}
        locator2 = {"index": 1}
        browserNewEgg.div(class_name="modal-footer").div(**locator2).button(
            **locator).click()

    time.sleep(2)

    #goes to secure checkout
    browserNewEgg.div(class_name="summary-actions").button().click()
Example #12
0
#!/usr/bin/env python3
from nerodia.browser import Browser
import re

loginsite = "https://mggym-borken.lms.schulon.org/login/index.php"

browser = Browser(browser='firefox')
browser.goto(loginsite)
usrn = browser.text_field(name="username")
usrn.value = ''
pswd = browser.text_field(name="password")
pswd.value = ''
browser.button(value='Login').click()

html = browser.html

#print(html:=browser.html)
matches = re.findall(
    '<span.*>Meine Kurse<\/span>.*href="(https:\/\/mggym-borken.lms.schulon.org\/course\/view.php\?id=\d+)">.*href="(https:\/\/mggym-borken.lms.schulon.org\/course\/view.php\?id=\d+)">.*href="(https:\/\/mggym-borken.lms.schulon.org\/course\/view.php\?id=\d+)">',
    html)
kurse = list(matches[0])
#print(kurse)

for kurs in kurse:
    browser.goto(kurs)
    html = browser.html
    matches = re.findall(
        'href="(https:\/\/mggym-borken\.lms\.schulon\.org\/mod\/resource\/view.php\?id=\d+)"><img src="https:\/\/mggym-borken\.lms\.schulon\.org\/theme\/image\.php\/classic\/core\/1587401819\/f\/pdf-24"',
        html)
    print(matches)
Example #13
0
# Based on http://watir.com/guides/form-example/

from nerodia.browser import Browser
from time import sleep  # needed to perform sleep
from faker import Faker  # needed for fake form data
import os  # needed for file path

# Setup
browser = Browser(browser='chrome')
browser.window().maximize()

# Navigate to the Page
browser.goto('a.testaddressbook.com')

# Authenticate and Navigate to the Form
browser.link(id='sign-in').click()
browser.text_field(data_test='email').set('*****@*****.**')
browser.text_field(data_test='password').set('password')
browser.button(name='commit').click()
browser.link(data_test='addresses').click()
browser.link(data_test='create').click()

# This uses the Faker Library to give us Random Data.
# Read more about Faker Library here: https://pypi.org/project/Faker/

fake = Faker()  # So we can use fake.name() instead of Faker().name()
browser.text_field(id='address_first_name').set(fake.first_name())
browser.text_field(id='address_last_name').set(fake.last_name())
browser.text_field(id='address_street_address').set(fake.street_address())
browser.text_field(id='address_secondary_address').set(
    fake.secondary_address())
from nerodia.browser import Browser

browser = Browser(browser='chrome')
browser.goto(
    'http://wp.curve.in.th/wp-login.php?loggedout=true&wp_lang=en_US&jetpack-sso-show-default-form=1'
)
t = browser.text_field(id='user_login')
t.value = '**'

t = browser.text_field(id='user_pass')
t.value = '***'

browser.button(id='wp-submit').click()
browser.wait_until(timeout=2,
                   interval=0.5,
                   method=lambda e: e.title.startswith("Dashboard"))

posts = []
for i in range(1, 6):
    browser.goto(f'http://wp.curve.in.th/wp-admin/edit.php?paged={i}')

    for t in browser.trs(class_name="type-post"):
        p = {}
        date = t.td(class_name="date").span().text
        date = date.replace("/", "-")
        p["date"] = date
        link = t.div(class_name="row-actions").span(
            class_name="view").link().href
        p["view_link"] = link

        p["name"] = link.replace("http://wp.curve.in.th/", "")
Example #15
0
from nerodia.browser import Browser

b = Browser(browser='chrome')
b.goto("http://toolsqa.com/automation-practice-form/")
print(b.title)

uploadfile = "/Users/Kerrrlo/Downloads/Photos/boss.jpeg"
b.file_field(id="photo").set(uploadfile)
Example #16
0
from nerodia.browser import Browser
import re
from selenium import webdriver
import json

BASE = "https://herdt-campus.com"

fp = webdriver.FirefoxProfile('/home/bf/.mozilla/firefox/a67xxtyb.auto')
driver = webdriver.Firefox(fp)

#browser = Browser(browser='firefox')

browser = Browser(driver)

browser.goto('https://bk-ostvest.lms.schulon.org/mod/url/view.php?id=16833')

usrn = browser.text_field(name='username')
usrn.value = ''
pswd = browser.text_field(name='password')
pswd.value = ''
browser.button(value='Login').click()

browser.button(value='Ich stimme zu!').click()

katalog = re.findall(
    r'<a class="catalog-nav-link" href="(\/category\/herdt-themen\/[\w\/\- ]*)">[\w\/\- ]*<\/a>',
    browser.html)

categorieDict = dict()

for category in katalog:
Example #17
0
from nerodia.browser import Browser

browser = Browser(browser='firefox')
browser.goto('https://myonlineportal.net/')

usrn = browser.text_field(name='username')
usrn.value = ''
pswd = browser.text_field(name='password')
pswd.value = ''
browser.button(value='Login').click()
browser.goto('https://myonlineportal.net/extend_account')
browser.button(value='Account verlängern!').click()
Example #18
0
from nerodia.browser import Browser

br = Browser(browser="firefox")
br.goto("https://www.w3schools.com/html/html_form_elements.asp")
br.element(css="textarea[cols='30']").send_keys("hello world")
br.element(css="textarea[cols='30']").send_keys([COMMAND + 't'])

browser.close()
Example #19
0
from time import sleep

REDIRECT_SLEEP_SEC = 2
def login():
    username = '******'
    password = ""
    browser.link(text='Log In').click()
    sleep(REDIRECT_SLEEP_SEC)
    # require 'pry'; binding.pry
    browser.text_field(name='username').set(username)
    browser.text_field(name='password').set(password)
    browser.input(class_name='twikiSubmit').click()
    sleep(REDIRECT_SLEEP_SEC)
    my_link = browser.element(text="Cheng Ji")
    print(my_link.html)

# if in the root:
# from selenium.webdriver.chrome.options import Options

# options = Options()
# options.add_argument('--no-sandbox')
# options.add_argument('--disable-dev-shm-usage')
# options.add_argument('--headless')
# options.add_argument('--disable-gpu')
# browser = Browser(browser='chrome', options=options)
browser = Browser(browser='chrome', headless=True)
# cannot using with
# with Browser(browser='chrome', headless=False) as browser:
browser.goto("http://wiki.fortinet.com/twiki/bin/view")
login()
# browser.close()
Example #20
0
class Bot(Thread):
    def __init__(self, candidate, url, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.email = config('email')
        self.password = config('password')

        self.candidate = candidate

        self._running = False

        self.url = url
        self.browser = None

        self.open()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.close()

    def open(self):
        print('abrindo browser')
        self.browser = Browser('firefox')
        self.browser.goto(self.url)
        self.browser.wait()

    def close(self):
        print('fechando browser')
        self.browser.close()

    def auth(self):
        self.condidate_div.click()

        # IFRAME MALDITO!
        # with self.browser.windows[1]
        # self.browser.

        # login = self.browser.input(id='login')
        # login.wait_for_present()
        # login.send_keys(self.email)
        #
        # password = self.browser.input(id='password')
        # password.wait_for_present()
        # password.send_keys(self.password)
        #
        # entrar = self.browser.button(text='Entrar')
        # entrar.wait_for_present()
        # entrar.click()

    @property
    def condidate_div(self):
        return self.browser.div(text=self.candidate)

    @property
    def captcha_div(self):
        return self.browser.div(class_name=[
            '_3xDixtS9TduMA-tXdgvxyM', '_2DsRxsoPgkhrq5exq-TSVO',
            '_2cZtCsRea_lK2Xi3dqwru'
        ])

    def votar_novamente(self):
        button = self.browser.button(text='Votar Novamente')
        if button.present:
            print('vou votar novamente!')
            button.click()
            sleep(2)

    def votar(self):
        candidate = self.condidate_div
        if candidate.present:
            print('candidato presente!')
            candidate.click()
            sleep(2)
            while candidate.present:
                captcha_div = self.captcha_div
                captcha_div.wait_for_exists()
                print('Achei o captcha!')
                img = captcha_div.img()
                print('Vou clickar!')
                img.click()
                sleep(5)

    def run(self):
        # self.open_browser()

        # self.auth()

        self._running = True
        while self._running:
            try:
                self.votar()
                self.votar_novamente()
            except Exception as e:
                pass

        self.browser.close()
Example #21
0
                        print(f'Found {match} in {browser.url}')
                    browser.back()
            elif 'Directory' in item.text:
                # print(f'Checking Folder {item.text}')
                browser.goto(browser.url + '/' +
                             item.text.replace('Directory', '').strip())
                file_recursion()
                browser.back()
    except:
        print('Empty Repo')


# start browser
browser = Browser(browser='chrome')
browser.window().maximize()
browser.goto('https://bitbucket.paya.com/projects')
browser.text_field(id='j_username').send_keys(os.environ['username'])
browser.text_field(id='j_password').send_keys(os.environ['passsword'])
browser.button(id='submit').click()
total_files_bb = 0
file_ending = re.compile(
    r'(\w+\.config\b|\w+\.cs\b|\w+\.vb\b|\w+\.js\b|\w+\.json\b|\w+\.txt\b|\w+\.yml\b)'
)
connectionstring = re.compile(
    r'([uU]ser\s[iI][dD]=[\S]+;|[pP]assword=[\S]+;|[dD]atabase=[\w0-9\-]+;|[sS]erver=[\w0-9\-\\]+;)+'
)

table = browser.table(id='projects-table')
print(f'Number of Projects = {sum(1 for e in table)-1}')
bad_strings = [
    'Description', 'AutomationCoreCode', '-old', "-OLD", 'APIGEE', 'Boomtown',
Example #22
0
from nerodia.browser import Browser
import pandas as pd
import time

browser = Browser(
    'chrome', headless=True
)  # Set Headless to True so the physical GUI of Chrome doesn't have to be used ⚡️
browser.goto('https://www.premierleague.com/stats/top/players/goals?se=274'
             )  # Now use the browser to navigate to the EPL Stats Page

time.sleep(5)  # Allow data time to load into HTML

goals = pd.read_html(
    browser.html
)[0]  # Use Pandas to fetch all the tables within the browser html, select the first table it finds ([0])

# When you've reached the end of the table, the Page Next button adds class 'inactive' to the page next element (div). Use browser tools to inspect the button on the last page to see for yourself.
# As we know this, we can keep clicking the page next button and scraping the table until the button is inactive. In Python we can use while loop:
while ((browser.div(
        class_name=["paginationBtn", "paginationNextContainer", "inactive"])
        ).exists == False):
    browser.div(
        class_name=["paginationBtn", "paginationNextContainer"]
    ).fire_event(
        'onClick'
    )  # fire onClick event on page next element. If it was a button element (not a div element), we could simply use .click()
    time.sleep(2)
    goals = goals.append(
        pd.read_html(browser.html)[0]
    )  # append the table from this page with the existing goals dataframe.
    print("Next Page")