Exemplo n.º 1
0
    def test_searchGoogle_2(self):
        self.driver.get("https://www.google.com")

        self.driver.find_element_by_xpath("//*[@name='q']").send_keys(
            "Hello World again")
        time.sleep(3)
        wait = webdriver(self.driver, 10)
        element = wait.until(expected_conditions.element_to_be_selected(By))
        print(self.driver.title)
        self.assertEquals("Google", self.driver.title)
version = platform.version()
current_directory = os.getcwd()

# Check for Version of Chrome

# Options 
#options = webdriver.ChromeOptions() 
#options.add_argument("download.default_directory=current_directory", "--headless")

# WebDriver Path for System
if platform.system() == ('Windows'):
    browser = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\chromedriver.exe")
elif platform.system() == ('Linux'):
    browser = webdriver.Chrome(executable_path='/home/rbarrett/Drivers/Google/Chrome/chromedriver_linux64/chromedriver')
elif platform.system() == ('Darwin'):
    browser = webdriver(executable_path='~/Drivers/Google/Chrome/chromedriver_mac64/chromedriver')
else:
    print("Are you sure you have the Selenium Webdriver installed in the correct path?")
      
# Parent URL
browser.get("https://invoice-generator.com/#/3")

# If Login
# Credentials NEEDS UNIT TEST
#username = browser.find_element_by_id("login")
#password = browser.find_element_by_id("password")
#username.send_keys(config['user']['name'])
#password.send_keys(config['user']['password'])

# Invoice Number
Exemplo n.º 3
0
class Keywords:
    def find_element_by_id(browser, id):
        try:
            return browser.find_element_by_id(id).get_attribute(
                'innerHTML').encode("ascii", "xmlcharrefreplace")
        except Exception as e:
            #print str(e)
            sys.exc_clear()
            return None

    def find_elements_by_tag_name(browser, tag_name):
        try:
            #print "No of rows", len(browser.find_elements_by_tag_name(tag_name)[5:])
            #print browser.find_elements_by_tag_name(tag_name)[5].get_attribute('innerHTML').encode("ascii", "xmlcharrefreplace")
            return browser.find_elements_by_tag_name(tag_name)[5:]
        except Exception as e:
            print str(e)
            sys.exc_clear()
            return None

    def find_all(soup, tag_name, attributes):
        try:
            #print len(soup.find_all(tag_name, attributes))
            return soup.find_all(tag_name, attributes)
        except Exception as e:
            print str(e)
            sys.exc_clear()
            return None

    def find(soup, tag_name):
        try:
            #print len(soup.find_all(tag_name))
            return soup.find(tag_name)
        except Exception as e:
            print str(e)
            sys.exc_clear()
            return None

    def webdriver():
        print "Instantiating Browsers..."
        browsers = list()
        try:
            firefox = webdriver.Firefox()
            print "Creating Firefox driver"
            browsers.append(firefox)
        except Exception as e:
            print "failed... could not create firefox... skipping"
            sys.exc_clear()
        try:
            chrome = webdriver.Chrome()
            print "Creating Chrome driver"
            browsers.append(chrome)
        except Exception as e:
            print "failed... could not create chrome... skipping"
            sys.exc_clear()
        try:
            ie = webdriver.Ie()
            print "Creating IE driver"
            browsers.append(ie)
        except Exception as e:
            print "failed... could not create IE... skipping"
            sys.exc_clear()
        print "done... okay\n"
        return browsers

    if __name__ == "__main__":
        print "Initializing..."
        browsers = webdriver()
        topDomainIDs = [2]
        print "Domains: ", topDomainIDs
        subDomainIDs = range(25)
        print "SubDomains: ", subDomainIDs, "\n"
        for topDomainID in topDomainIDs:
            print "Current Domain:", topDomainID
            for subDomainID in subDomainIDs:
                rid = 0
                file = open(
                    'keywords-publications-citations-top' + str(topDomainID) +
                    '-sub' + str(subDomainID) + '.csv', 'wb')
                file.write("#,Keyword,Publications,Citations\n")
                print "Current SubDomain:", subDomainID
                start = 1
                end = 100
                url = "http://academic.research.microsoft.com/RankList?entitytype=8&topDomainID={0}&subDomainID={1}&last=0&start={2}&end={3}".format(
                    topDomainID, subDomainID, start, end)
                ranklistresult = None
                k = 0
                while ranklistresult == None:
                    browser = random.choice(browsers)
                    browser.get(url)
                    ranklistresult = find_element_by_id(
                        browser, "ctl00_MainContent_lblResultMessage")
                    if ranklistresult == None:
                        t = random.randrange(pow(2, k)) * random.random()
                        print "Retrying in", t, "seconds"
                        time.sleep(t)
                        if k <= 10:
                            k = k + 1
                k = 0
                ranklistresult = int(
                    ranklistresult[ranklistresult.index('of'):].replace(
                        'of ', '').replace(' results', '').replace(',', ''))
                print "Total:", ranklistresult
                ranklistresult = 1000
                while start <= ranklistresult:
                    url = "http://academic.research.microsoft.com/RankList?entitytype=8&topDomainID={0}&subDomainID={1}&last=0&start={2}&end={3}".format(
                        topDomainID, subDomainID, start, end)
                    rows = None
                    while rows == None or rows == [] or rows == '':
                        browser = random.choice(browsers)
                        browser.get(url)
                        rows = find_elements_by_tag_name(browser, 'tr')
                        if rows == None or rows == [] or rows == '':
                            t = random.randrange(pow(2, k)) * random.random()
                            print "Retrying in", t, "seconds"
                            time.sleep(t)
                            if k <= 10:
                                k = k + 1
                    k = 0
                    for row in rows:
                        row = row.get_attribute('innerHTML').encode(
                            "ascii", "xmlcharrefreplace")
                        soup = BeautifulSoup(row)
                        keyword = str(find(soup, 'a').text)
                        publications = int(
                            find_all(soup, 'td',
                                     {'class': 'staticOrderCol'})[0].text)
                        citations = int(
                            find_all(soup, 'td',
                                     {'class': 'staticOrderCol'})[1].text)
                        rid = rid + 1
                        print rid, keyword, publications, citations
                        file.write("{0},{1},{2},{3}\n".format(
                            rid, keyword, publications, citations))
                    start = start + 100
                    end = end + 100
                file.close()
        print "done... finished... okay"
        print "closing browsers"
        for browser in browsers:
            browser.close()
        print "see file output"
Exemplo n.º 4
0
from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver()

headers = {
    'Access-Control-Allow-Origin':
    '*',
    'Access-Control-Allow-Methods':
    'GET',
    'Access-Control-Allow-Headers':
    'Content-Type',
    'Access-Control-Max-Age':
    '3600',
    'User-Agent':
    'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'
}

url = urllib.request.urlopen("https://br.ifunny.co/fun/y5Cr6aT36")
Exemplo n.º 5
0
def my_func(im):
    WINDOW_SIZE = "834, 596"
    kernel = np.ones((2, 2), np.uint8)
    osplat = platform.system()
    chrome_options = Options()
    print(im)
    # chrome_options.add_argument('--disable-gpu')
    # chrome_options.add_argument("--log-level=3")
    # chrome_options.add_argument("--headless")
    chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
    # chrome_options.add_argument("--window-size=%s" % (853, 821))
    driver = webdriver.Chrome(
        chrome_options=chrome_options) if osplat == "Windows" else webdriver(
            os.path.join(os.path.abspath(os.path.dirname(__file__),
                                         "chromedriver"),
                         chrome_options=chrome_options))
    img = cv2.imread(im)
    final_wide = 800
    r = float(final_wide) / img.shape[1]
    dim = (final_wide, int(img.shape[0] * r))
    img = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.medianBlur(gray, 3)
    ret, gray = cv2.threshold(gray, 130, 255, 0)
    cv2.imwrite('mol.jpg', gray)
    driver.get('https://cactus.nci.nih.gov/cgi-bin/osra/index.cgi')
    driver.find_element_by_css_selector('[type="file"]').send_keys(
        os.path.join(os.path.abspath(os.path.dirname(__file__)), "mol.jpg"))
    driver.find_element_by_css_selector('[id="b_upload"]').click()
    time_old = time.time()
    tes_zag = ""
    while tes_zag == "":
        try:
            if (time.time() - time_old > 15):
                print('some error, please try again')
                driver.quit()
                return (0)
            while driver.find_element_by_css_selector(
                    '[alt="Chemical Structure"]') is None:
                pass
            if driver.find_element_by_css_selector(
                    '[alt="Chemical Structure"]'):
                tes_zag = "yes"
        except:
            pass
    try:
        time.sleep(0.2)
        driver.find_element_by_css_selector('[x="9390"][y = "750"]').click()
        time.sleep(2)
        driver.find_element_by_css_selector(
            '[class="gwt-MenuItem"][id="gwt-uid-9"]').click()
        time.sleep(2.5)
        driver.find_element_by_css_selector(
            '.gwt-TextArea.gwt-TextArea-readonly').send_keys(
                Keys.CONTROL, "c")
        tk = Tk()
        tk.withdraw()
        with open("pars.html", "w") as fd:
            fd.write(tk.clipboard_get())
        driver.quit()
        return (1)
    except:
        return (0)
Exemplo n.º 6
0
'''
Created on 03-May-2019

@author: priyanka.gupta
'''

#Import webdriver module from selenium package
from selenium import webdriver

#Path of chrome driver for windows 
chrome_driver_path = "D:\SeleniumProjects\TeachMeSelenium\chromedriver.exe"
#For Mac please comment the above line and uncomment the below line
#chrome_driver_path = "/usr/local/bin/chromedriver"

#Create object of Chrome
driver=webdriver(chrome_driver_path)
#Navigate browser to practice.teachmeselenium.com
driver.get("http://practice.teachmeselenium.com")
#Type iPhone 7 in the search box
driver.find_element_by_name("s").send_keys("iPhone 7")
#Click on Search button
driver.find_element_by_class_name("bgs-search-submit").click()
#In the next page capture price of the product
price = driver.find_element_by_class_name("price").text
print("Price of the product is " + price)
#Click on Add to Cart button
driver.find_element_by_name("add-to-cart").click();
#Click on View cart button
driver.find_element_by_link_text("View cart").click();
#Quit driver and close browser
driver.quit()
Exemplo n.º 7
0
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver=webdriver.firefox()
driver.get("https://demo.actitime.com")
try:
    element=webdriver(driver,10).until
 def setUp(self):
     self.wd = webdriver()
     self.wd.implicitly_wait(5)
 def setUp(self):
     self.wd = webdriver()
     self.wd.implicitly_wait(60)
Exemplo n.º 10
0
def configured_screen_shot_func(website):
    screenshot_func = partial(screenshot_string_return,
                              configured_driver_input=webdriver())
    return screenshot_func(website)
Exemplo n.º 11
0
 def __init__(self, webdriver):
     self._driver = webdriver()
Exemplo n.º 12
0
 def __init__(self):
     self.driver = webdriver(
         'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe'
     )
     self.driver.implicitly_wait(10)
     self.driver.get('http://oa.byxem.com')
Exemplo n.º 13
0
 def __init__(self):
     #实例化无界面浏览器
     self.brower = webdriver(
         executable_path=
         'C:\\soft\\phantomjss\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe'
     )