def login(self, browser):
		"""
		利用配置文件和初始化信息进行模拟登陆
		:param:浏览器对象,已打开原始的登录页面
		:return:浏览器对象
		"""
		browser.get( self.config['BussinessStaffURL'] )
		browser.switch_to.frame( browser.find_element_by_tag_name("iframe") )
		userNameInput = browser.find_element_by_name("TPL_username")
		userNameInput.clear()
		userNameInput.send_keys( self.username+Keys.TAB+self.password+Keys.RETURN )
		browser.switch_to.default_content()
		loopKey = True
		while loopKey:
			try:
				WebDriverWait( browser, 4 ).until( EC.presence_of_element_located( ( By.CSS_SELECTOR, "ul>li>a>div>strong>span" ) ) )
				loopKey = False
			except Exception:
				browser.switch_to.frame( browser.find_element_by_tag_name("iframe") )
				passwordInput  = WebDriverWait(browser,10).until( EC.presence_of_element_located( (By.ID, "TPL_password_1") ) )
				passwordInput.clear()
				passwordInput.send_keys( self.password )
				checkCodeInput = WebDriverWait(browser,10).until( EC.presence_of_element_located( (By.ID,"J_CodeInput_i") ) )
				checkCode = enterbox("请输入验证码(不区分大小写)","验证码输入","", True)
				checkCodeInput.send_keys(checkCode+Keys.RETURN)
				browser.switch_to.default_content()
				loopKey = True

		return browser
 def login_adriaticapress(self):
     '''Creazione webdriver e procedura di login in adriatipress
     '''
     try:
         with open('secrets.txt') as credentials_file:
             credentials_file_list = list(credentials_file.readlines())
             username = credentials_file_list[0].strip()[9:]
             password = credentials_file_list[1].strip()[9:]
     except FileNotFoundError:
         self.msg = QMessageBox()
         self.msg.setText('File credenziali non presente')
         self.msg.setWindowTitle('testtitolo')
         self.msg.setStandardButtons(QMessageBox.Ok)
         return self.msg.exec_()
     if os.name == 'nt':
         self.dr = webdriver.Chrome('chromedriver.exe')
     else:
         self.dr = webdriver.Chrome()
     self.dr.maximize_window()
     self.dr.get('{}Login.htm'.format(ip_ap))
     time.sleep(5)
     username_field = WebDriverWait(self.dr, 15).until(EC.presence_of_element_located((By.ID, 'txtUsername')))
     password_field = WebDriverWait(self.dr, 15).until(EC.presence_of_element_located((By.ID, 'txtPassword')))
     username_field.clear()
     username_field.send_keys(username)
     password_field.clear()
     password_field.send_keys(password)
     password_field.send_keys(Keys.RETURN)
     time.sleep(5)
Exemple #3
0
 def live_stats_update(self):
     self.driver.get(self.get_url('/'))
     WebDriverWait(self.driver, 10).until(
         expected_conditions.presence_of_element_located((By.CLASS_NAME, 'ng-binding'))
     )
     self.claim_and_return_an_item()
     WebDriverWait(self.driver, 10).until(
         expected_conditions.presence_of_element_located((By.XPATH, 'id("leaderboard-recent")//tbody/tr[2]'))
     )
     self.assertEqual(
         self.driver.find_element_by_xpath('id("leaderboard-recent")//tbody/tr[1]/td[3]').text,
         '20'
     )
     self.assertEqual(
         self.driver.find_element_by_xpath('id("leaderboard-totals")//tbody/tr[1]/td[2]').text,
         '2'
     )
     self.assertEqual(
         self.driver.find_element_by_xpath('id("leaderboard-totals")//tbody/tr[1]/td[3]').text,
         '40'
     )
     self.assertEqual(
         self.driver.find_element_by_xpath('id("globalstats")//strong[1]').text,
         '40'
     )
     self.assertEqual(
         self.driver.find_element_by_xpath('id("globalstats")//strong[2]').text,
         '2'
     )
Exemple #4
0
 def login_with_qr(self):
     self.storage.clear()
     self.driver.refresh()
     currentsrc = None
     currentfig = None
     wait = WebDriverWait(self.driver,30)
     while True:
         if self.storage.get('WAToken1') == None:
             reloadbutton = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/div/div/div/div[1]/div[1]/div')))
             if(reloadbutton.get_attribute('class') == "idle"):
                 reloadbutton.click()
             imagelement = wait.until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/div/div/div/div[1]/div[1]/div/img')))
             tmp = imagelement.get_attribute('src')
             if currentsrc == tmp:
                 time.sleep(1)
                 continue
             else:
                 currentsrc = tmp
                 if currentfig!=None:
                     plt.clf()
                 currentfig = self.show_current_qr(currentsrc,currentfig)
                 continue
         else:
             if currentfig!=None:
                 plt.close(currentfig)
             break
def main(webdriver):
    login(webdriver)
    submit_button = webdriver.find_element_by_class_name('Submit')
    submit_button.click()

    try:
        WebDriverWait(webdriver, int(os.environ.get('TIMEOUT'))).until(
            EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Date of birth:')]"))
        )
    except TimeoutException as error:
        raise Exception('Timed out waiting for page to load')

    multi_driver_check = webdriver.find_elements_by_xpath("//*[contains(text(), 'Date of birth:')]")  # Array where len(check) will tell you how many vehicles in policy
    if len(multi_driver_check) >= 2:
        remove_driver_buttons = webdriver.find_elements_by_xpath('//button[text()="Remove"]')
        if remove_driver_buttons and len(remove_driver_buttons) >= 2:
            remove_driver_buttons[1].click()
        else:
            raise Exception('Could not find driver_remove button')
        webdriver.find_element_by_xpath('//a[@href="/account/drivers/01/remove"]').click()
        try:
            WebDriverWait(webdriver, int(os.environ.get('TIMEOUT', 5))).until(
                EC.presence_of_element_located((By.NAME, 'requester_name'))
            )
        except TimeoutException:
            raise Exception('Timed out waiting for requester_name_field')

        requester_name_field = Select(webdriver.find_element_by_name('requester_name'))
        requester_name_field.select_by_index(1)
        driver_remove_reason_field = Select(webdriver.find_element_by_name('driver_remove_reason'))
        driver_remove_reason_field.select_by_visible_text('No longer lives in the household')
        date_fields = webdriver.find_elements_by_name("date_input")
        date_fields[0].send_keys('{}'.format(datetime.date.today() + datetime.timedelta(days=2)))
        other_frequent_driver_field = Select(webdriver.find_element_by_name('other_frequent_driver'))
        other_frequent_driver_field.select_by_visible_text('None')
        vehicle_usage_field = Select(webdriver.find_element_by_name('vehicle_usage'))
        vehicle_usage_field.select_by_visible_text('Pleasure')
        vehicle_annual_kms_field = webdriver.find_element_by_name('vehicle_annual_kms')
        vehicle_annual_kms_field.send_keys('90')
        date_fields = webdriver.find_elements_by_name("date_input")
        date_fields[0].send_keys('{}'.format(datetime.date.today() + datetime.timedelta(days=2)))

        vehicle_usage_fields = webdriver.find_elements_by_xpath('//select[@name="vehicle_usage"]')
        annual_kms_fields = webdriver.find_elements_by_name('vehicle_annual_kms')
        if vehicle_usage_fields:
            for field in vehicle_usage_fields:
                select_vehicle_usage_field = Select(field)
                select_vehicle_usage_field.select_by_visible_text('Pleasure')
        if annual_kms_fields:
            for field in annual_kms_fields:
                field.send_keys('123')

        for num in range(1, len(multi_driver_check) + 1):
            stringified_num = '0{}'.format(num)
            x_principal_driver_field = webdriver.find_elements_by_xpath("//select[@name={0}]".format("'veh_{}_principal_driver'".format(stringified_num)))
            if x_principal_driver_field:
                Select(x_principal_driver_field[0]).select_by_index(1)
    else:
        raise Exception('Can only remove driver if policy has 2+ drivers')
        webdriver.close()
 def search(self, query):
     self.ensure_login()
     self.driver.switch_to_default_content()
     try:
         nav_search = WebDriverWait(self.driver, 10).until(
                 EC.presence_of_element_located((By.ID, 'nav-search'))
         )
         nav_search.click()
         self.ensure_frame('suggest')
         form = WebDriverWait(self.driver, 10).until(
                 EC.presence_of_element_located((By.TAG_NAME, 'form'))
         )
         search_bar = form.find_element_by_tag_name('input')
         search_bar.send_keys(query)
         show_results = WebDriverWait(self.driver, 10).until(
                 EC.presence_of_element_located((By.XPATH, '//*[@class="results"]/descendant::a'))
         )
         show_results.click()
         self.driver.switch_to_default_content()
         wrapper = WebDriverWait(self.driver, 10).until(
                 EC.presence_of_element_located((By.CLASS_NAME, 'front'))
         )
         iframe = wrapper.find_element_by_tag_name('iframe')
         self.driver.switch_to_frame(iframe)
         songs = WebDriverWait(self.driver, 10).until(
                 EC.presence_of_element_located((By.TAG_NAME, 'tbody'))
         )
         first_song = songs.find_element_by_tag_name('tr')
         first_song.click()
         first_song.send_keys(Keys.RETURN)
     except:
         print('Can\'t find element...')
         print(traceback.format_exc())
    def test_channelAnimatorBoundaryAnimation(self):
        driver = self.driver 

        # Open a test image so we have something to animate
        Util.load_image( self, driver, "Default")

        # Find and record the last valid value of the animation
        self._getLastValue( driver, "Channel" )
        lastChannelValue = self._getCurrentValue( driver, "Channel" )

        # Find and click the lower spin box
        lowerBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelLowerBoundSpin']/input")))
        driver.execute_script( "arguments[0].scrollIntoView(true);", lowerBoundText)
        lowerBoundText.click()

        # Change the lower bound value
        lowerBoundValue = Util._changeElementText(self, driver, lowerBoundText, 1)

        # Find and click the upper spin box
        upperBoundText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='ChannelUpperBoundSpin']/input")))
        driver.execute_script( "arguments[0].scrollIntoView(true);", upperBoundText)
        upperBoundText.click()

        # Change the upper bound value 
        upperBoundValue = Util._changeElementText( self, driver, upperBoundText, int(lastChannelValue)-1)

        # Allow test image to animate for 2 seconds
        self._animateForward( driver, "Channel" )
        time.sleep(2)

        # Check that the lower and upper bound values did not change during animation
        lowerBound = lowerBoundText.get_attribute("value")
        upperBound = upperBoundText.get_attribute("value")
        self.assertEqual( int(lowerBound), int(lowerBoundValue), "Lower bound channel value changed during animation")
        self.assertEqual( int(upperBound), int(upperBoundValue), "Upper bound channel value changed during animation")
Exemple #8
0
def downloadYear(driver, url):
    driver.get(url)
    print(driver.title)
     
    # find button for 统计数据
    driver.find_element_by_link_text("统计数据").click()
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "div.dhmltable-biaotou"))
    )
    records = element.text.strip()
    print(records)        
     
    print("=== page: 1 ===")
    downloadPage(driver)
     
    # page numbers
    pages = records.split("  ")[-1].split(" ")
    for page in pages[1:]:
        driver.find_element_by_link_text(page).click()
        element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, "div.dhmltable-biaotou"))
        )
          
        print("=== page: " + page + " ===")
        downloadPage(driver)
  def test_deleteSafariUserData(self):

      logger.debug(inspect.stack()[0][3])

      #self.driver.execute_script('mobile: activateApp', {'bundleId': 'com.apple.Preferences'})
      
      #self.driver.execute_script('mobile: scroll', {'': ''});

      

      #ACTIONCHAINS (AKA MOUSE) IS NOT AVAILABLE FOR IOS, USE TOUCH ACTIONS INSTEAD
     # actions = ActionChains(self.driver)
      #actions.move_to_element(element)
      #actions.click(element)
      #actions.perform()

      #WHATS THE DIFF BTWN EXECUTE_MOBILE_CMDS AND TOUCH ACTIONS??
      #THIS TEST TAKES LONG TIME...TOO LONG...LIKE 3 MINUTES 
      self.driver.execute_script('mobile:scroll',{'name':"Safari" } ) #APPIUM BUG, LIMITED SCROLLING...
      self.driver.execute_script('mobile:scroll',{'name':"Safari" } ) #...NEEDS TO BE CALLED TWICE
      element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ACCESSIBILITY_ID, "Safari")))
      self.driver.execute_script('mobile: tap', {'element': element, 'x': 0 , 'y': 0  }) #(0,0) works
      self.driver.execute_script('mobile:scroll',{'name':"Clear History and Website Data" } ) #...NEEDS TO BE CALLED TWICE
      self.driver.execute_script('mobile:scroll',{'name':"Clear History and Website Data" } ) #...NEEDS TO BE CALLED TWICE
      element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ACCESSIBILITY_ID, "Clear History and Website Data")))
      self.driver.execute_script('mobile: tap', {'element': element, 'x': 0 , 'y': 0  }) #(0,0) works
      element = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ACCESSIBILITY_ID, "Clear History and Data")))
      self.driver.execute_script('mobile: tap', {'element': element, 'x': 0 , 'y': 0  }) #(0,0) works  
Exemple #10
0
    def test_histogramLinkRemoval(self):
        driver = self.driver
        browser = selectBrowser._getBrowser()

        # Wait for the image window to be present (ensures browser is fully loaded)
        imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))

        # Find the Histogram window
        histWindow = self._getHistogramWindow( driver )
        ActionChains(driver).click(histWindow).perform()

        # Open Link settings for the Histogram window
        linkMenuButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[text()='Links...']")))
        ActionChains(driver).click( linkMenuButton ).perform()

        # Remove link from the Histogram to the main image window
        Util.remove_main_link( self, driver, imageWindow )

        # Load an image
        Util.load_image( self, driver, "Default")

        # Find and select the histogram window
        histWindow = self._getHistogramWindow( driver )
        ActionChains(driver).click( histWindow ).perform()

        # Click the settings button to expose the settings
        self._openHistogramSettings( driver )

        # Check that the histogram values are default values
        newMaxZoomValue = self._getTextValue( driver, "histogramZoomMaxValue")
        self.assertEqual( float(newMaxZoomValue), 1, "Histogram is linked to image after link was removed")
Exemple #11
0
    def test_histogramChangeLinks(self):
        driver = self.driver
        browser = selectBrowser._getBrowser()

        # Wait for the image window to be present (ensures browser is fully loaded)
        imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))

        # Find and select the Histogram window
        histWindow = self._getHistogramWindow( driver )
        ActionChains(driver).click( histWindow ).perform()

        # Click the settings button to expose the settings
        self._openHistogramSettings( driver )

         # Open Link settings for the Histogram window
        linkMenuButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[text()='Links...']")))
        ActionChains(driver).click( linkMenuButton ).perform()

        # Remove the link from the Histogram to the main image window
        Util.remove_main_link( self, driver, imageWindow )

        # Load an image in a separate window
        imageWindow2 = Util.load_image_different_window( self, driver, "aH.fits")

        # Open link settings for the Histogram
        ActionChains(driver).click( histWindow ).perform()
        linkMenuButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[text()='Links...']")))
        ActionChains(driver).click( linkMenuButton ).perform()

        # Link the Histogram to the second image
        Util.link_second_image( self, driver, imageWindow2)

        # Check that the histogram values are not default values
        newMaxZoomValue = self._getTextValue( driver, "histogramZoomMaxValue")
        self.assertNotEqual( float(newMaxZoomValue), 1, "Histogram did not update to newly linked image")
Exemple #12
0
    def test_histogramRemoveImage(self):
        driver = self.driver
        timeout = selectBrowser._getSleep()

        # Wait for the image window to be present (ensures browser is fully loaded)
        imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))

        # Load an image
        Util.load_image( self, driver, "Default")

        # Click on the Data->Close->Image button to close the image
        imageWindow = driver.find_element_by_xpath( "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")
        ActionChains(driver).double_click( imageWindow ).perform()
        dataButton = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Data']/..")))
        ActionChains(driver).click( dataButton ).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(
            Keys.ARROW_RIGHT).send_keys(Keys.ENTER).perform()

        # Find and select the Histogram window
        histWindow = self._getHistogramWindow( driver )
        ActionChains(driver).click( histWindow ).perform()
        time.sleep( timeout )

        # Click the settings button to expose the settings
        self._openHistogramSettings( driver )

        # Check that the histogram values are restored to default values
        newMaxZoomValue = self._getTextValue( driver, "histogramZoomMaxValue")
        print "Zoom max value=", newMaxZoomValue
        self.assertEqual( float(newMaxZoomValue), 1, "Default values were not restored after image removal")
Exemple #13
0
    def _getHistogramWindow(self, driver):
        # First see if there is a histogram window already there
        histWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowHistogram']")))

        if histWindow is None:
            print "Making popup histogram"
            #Find a window capable of loading an image
            imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
            if imageWindow is None:
                print "No way to get a histogram window"
                return

            # Show the context menu
            ActionChains(driver).context_click( imageWindow ).perform()

            # Click the popup button
            popupButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Popup']/..")))
            self.assertIsNotNone( popupButton, "Could not click popup button in the context menu")
            ActionChains(driver).click( popupButton ).perform()

            # Look for the histogram button and click it to open the histogram dialog
            histogramButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div/div[text()='Histogram']/..")))
            self.assertIsNotNone( histogramButton, "Could not click histogram button on popup subcontext menu")
            ActionChains(driver).click( histogramButton ).perform()

            # We should now see a histogram popup window
            histWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowHistogram']")))
            self.assertIsNotNone( histWindow, "Could not popup a histogram")

        return histWindow
 def test_login_and_post(self):
     # Go to the coop home page  
     self.driver.get("https://bc.libraries.coop/")
     # Log in
     self.driver.find_element_by_id("loginbtn").click()
     usernameField_present = EC.presence_of_element_located((By.ID, 'user_login'))
     WebDriverWait(self.driver, 10).until(usernameField_present)
     self.driver.find_element_by_id("user_login").send_keys(self.config['account']['username'])
     time.sleep(2)
     self.driver.find_element_by_id("user_pass").send_keys(self.config['account']['password'])
     time.sleep(2)
     self.driver.find_element_by_id("user-submit").click()
     time.sleep(2)
     # Navigate to My Dashboard
     self.driver.find_element_by_id("loginbtn").click()
     dashboardButton_present = EC.presence_of_element_located((By.LINK_TEXT, 'My Dashboard'))
     WebDriverWait(self.driver, 10).until(dashboardButton_present)
     self.driver.find_element_by_link_text("My Dashboard").click()
     WebDriverWait(self.driver, 10).until(EC.title_contains("Dashboard |"))
     # Navigate to test group, write and publish a post
     self.driver.find_element_by_xpath("//span[@class='group-title']").click()
     WebDriverWait(self.driver, 10).until(EC.title_contains("Home | Maple Public Library |"))
     self.driver.find_element_by_xpath("//textarea[@id='whats-new'][@name='whats-new']").send_keys(
         "This is a test post by Selenium Webdriver")
     self.driver.find_element_by_xpath(
         "//input[@id='aw-whats-new-submit']").send_keys("\n") # NOTE: Need to send "\n" instead of click for some weird wordpress buttons..
     # Check that the post is present, then delete it
     post_present = EC.presence_of_element_located((
         By.XPATH, "//div[@class='activity-inner']/p[text()='This is a test post by Selenium Webdriver']/../../div[@class='activity-meta']/a[text()='Delete']"))
     WebDriverWait(self.driver, 10).until(post_present)
     self.driver.find_element_by_xpath(
         "//div[@class='activity-inner']/p[text()='This is a test post by Selenium Webdriver']/../../div[@class='activity-meta']/a[text()='Delete']").send_keys("\n")
Exemple #15
0
def get_browser(username, password):
    """Get an instance of a firefox browser"""

    browser = webdriver.Firefox()
    browser.set_window_size(1020, 800)

    # set username
    browser.get('https://www.cgd.pt')
    elem = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, 'input_cx1'))
    )
    elem.send_keys(username + Keys.ENTER)

    # close warnings
    elem = WebDriverWait(browser, 10).until(
        EC.element_to_be_clickable((By.XPATH, '//*[@title="Fechar Aviso"]'))
    )
    elem.click()

    # add password
    elem = WebDriverWait(browser, 10).until(
        EC.presence_of_element_located((By.ID, 'passwordInput'))
    )
    elem.send_keys(password + Keys.ENTER)

    # close warnings
    elem = WebDriverWait(browser, 10).until(
        EC.element_to_be_clickable((By.CLASS_NAME, 'botao_ok'))
    )
    elem.click()

    return browser
Exemple #16
0
    def test_statsAnimation(self):
        driver = self.driver

        # Load a test image with animation
        Util.load_image( self, driver, "Default")

        # Move to the center of the image window so data appears in the Stats Window
        imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
        ActionChains(driver).move_to_element( imageWindow ).perform()

        # Get the Statistics of the loaded image 
        statsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
        statsText = statsText.get_attribute('textContent')   

        # Click the forward animation button
        forwardAnimateButton = driver.find_element_by_xpath("//div[@class='qx-toolbar']/div[@class='qx-button'][2]")
        self.assertIsNotNone( forwardAnimateButton, "Could not find forward animation button")
        driver.execute_script( "arguments[0].scrollIntoView(true);", forwardAnimateButton)
        ActionChains(driver).click( forwardAnimateButton ).perform()
        time.sleep(3)

        # Move to the center of the image window so data appears in the Stats Window
        imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
        ActionChains(driver).move_to_element( imageWindow ).perform()
        
        # Sometimes text does not appear, therefore move mouse cursor
        ActionChains(driver).move_by_offset( 100, 100 ).perform()

        # Get the Statistics of the loaded image 
        newStatsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
        newStatsText = newStatsText.get_attribute('textContent')   

        # Check that the Statistics text changed when image in the image window was changed
        self.assertNotEqual( newStatsText, statsText, "Stats text did not update during animation of the image")
Exemple #17
0
    def test_statsAddLink(self):
        driver = self.driver 
        time.sleep(5)

        # Load a different image in a different window
        imageWindow2 = Util.load_image_different_window( self, driver, "aK.fits")

        # Find and click on the Statistics window 
        statsWindow = driver.find_element_by_xpath("//div[@id='Statistics']")
        self.assertIsNotNone( statsWindow, "Could not find statistics window")
        ActionChains(driver).click( statsWindow ).perform()

        # In Stastics context menu, open Link Settings
        ActionChains(driver).context_click( statsWindow ).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()

        # Add a link to the new image window
        imageWindow2 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@id='CasaImageLoader2']")))
        ActionChains(driver).move_to_element( statsWindow ).click( statsWindow ).drag_and_drop( statsWindow, imageWindow2).perform()

        # Exit links
        ActionChains(driver).move_to_element( statsWindow ).context_click( statsWindow ).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform()

        # Move to the center of the image window so data appears in the Stats Window
        ActionChains(driver).move_to_element( imageWindow2 ).perform()
        
        # Sometimes text does not appear, therefore move mouse cursor
        ActionChains(driver).move_by_offset( 100, 100 ).perform()

        # Check that the Stastics window is not linked to the main image window
        statsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
        statsText = statsText.get_attribute('textContent')        
        
        # Check that the Default sky text appears in the Stats Window
        statsText = statsText.startswith("Default sky")
        self.assertEqual( statsText, 0, "Statistics window should not be linked to multiple windows")
Exemple #18
0
def accessModule(mainCfg,driver,moduleIDText):
    # Wait for span (with the access to the modules of ExpressoV3) to be clickable

    modulesOptionPath = 'html/body/div[1]/div[2]/div/div/div/div[3]/div/div/div/div[1]/div[1]/ul/li[1]/a[1]'
    WebDriverWait(driver, mainCfg['timeout']).until(EC.element_to_be_clickable((By.XPATH,modulesOptionPath)))
    driver.find_element_by_xpath(modulesOptionPath).click()

    # Find the menu with the options
    modulesMenuPath = '//ul/div/div/ul'
    WebDriverWait(driver, mainCfg['timeout']).until(EC.visibility_of_element_located((By.XPATH,modulesMenuPath)))
    modulesMenu = driver.find_element_by_xpath(modulesMenuPath)

    # Click in the option of the informed module
    modulesMenu.find_element_by_xpath("//span[contains(@class,'x-menu-item-text') and contains(text(),'" + moduleIDText + "')]").click()

    # wait for the window of the informed module
    modulekWindowPath = "//span[contains(@class,'x-tab-strip-text') and contains(text(),'" + moduleIDText + "')]"
    WebDriverWait(driver, mainCfg['timeout']).until(EC.presence_of_element_located((By.XPATH,modulekWindowPath)))

    # Verify if all the 3 sections are visible
    # west panel
    sectionPath = 'html/body/div[1]/div[2]/div/div/div/div[4]/div/div/div[3]/div/div[2]'
    WebDriverWait(driver,mainCfg['timeout']).until(EC.presence_of_element_located((By.XPATH,sectionPath)))

    # center panel - top
    sectionPath = 'html/body/div[1]/div[2]/div/div/div/div[4]/div/div/div[2]/div/div/div'
    WebDriverWait(driver,mainCfg['timeout']).until(EC.presence_of_element_located((By.XPATH,sectionPath)))

    # center panel - bottom
    sectionPath = 'html/body/div[1]/div[2]/div/div/div/div[4]/div/div/div[2]/div/div/div'
    WebDriverWait(driver,mainCfg['timeout']).until(EC.presence_of_element_located((By.XPATH,sectionPath)))

    print "debug 00"
Exemple #19
0
    def test_statsAddImage(self):
        driver = self.driver

        # Load a large test image. 
        Util.load_image( self, driver, "aH.fits")

        # Move to the center of the image window so data appears in the Stats Window
        imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
        ActionChains(driver).move_to_element( imageWindow ).perform()

        # Get the Statistics of the loaded image 
        statsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
        statsText = statsText.get_attribute('textContent')        
        
        # Load a different image in the same window
        Util.load_image( self, driver, "aK.fits")

        # Move to the center of the image window so data appears in the Stats Window
        ActionChains(driver).move_to_element( imageWindow ).perform()

        # Sometimes text does not appear, therefore move mouse cursor
        ActionChains(driver).move_by_offset( 100, 100 ).perform()

        # Get the Statistics of the loaded image 
        newStatsText = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.boundWidgets.Label']")))
        newStatsText = newStatsText.get_attribute('textContent')

        # Check that the Statistics text changed when new image was loaded
        self.assertNotEqual( newStatsText, statsText, "Stats text did not update when new image was loaded in main image window")
Exemple #20
0
 def test_it(self):
     browser.get(self.login_url)
     self.assertEqual(browser.title, 'Auth Page')
     browser.find_element_by_id('github').submit()
     self.assertEqual(browser.title,
                      b'Sign in \xc2\xb7 GitHub'.decode('utf-8'))
     form = browser.find_element_by_id('login')
     login = form.find_element_by_name('login')
     login.send_keys(self.login)
     passwd = form.find_element_by_name('password')
     passwd.send_keys(self.password)
     form.find_element_by_name('commit').submit()
     find_title = EC.title_is('Authorize access to your account')
     find_result = EC.presence_of_element_located((By.ID, 'result'))
     WebDriverWait(browser, 2).until(
         lambda driver: find_title(driver) or find_result(driver))
     if browser.title == 'Authorize access to your account':
         btn = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.NAME, 'authorize')))
         btn.click()
         result = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.ID, 'result')))
     else:
         result = browser.find_element_by_id('result')
     self.assertEqual(browser.title, 'Result Page')
     result = browser.find_element_by_id('result').text
     result = json.loads(result)
     self.assertTrue('profile' in result)
     self.assertTrue('credentials' in result)
     self.assertTrue('displayName' in result['profile'])
     self.assertTrue('accounts' in result['profile'])
Exemple #21
0
 def test_it(self):
     browser.get(self.login_url)
     self.assertEqual(browser.title, 'Auth Page')
     browser.find_element_by_id('live').submit()
     WebDriverWait(browser, 2).until(
         EC.presence_of_element_located((By.NAME, 'login')))
     self.assertEqual(browser.title,
                      'Sign in to your Microsoft account')
     login = browser.find_element_by_name('login')
     login.send_keys(self.login)
     passwd = browser.find_element_by_name('passwd')
     passwd.send_keys(self.password)
     passwd.submit()
     find_title = EC.title_is('Allow access?')
     find_result = EC.presence_of_element_located((By.ID, 'result'))
     WebDriverWait(browser, 2).until(
         lambda driver: find_title(driver) or find_result(driver))
     if browser.title == 'Allow access?':
         btn = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.NAME, 'submitYes')))
         btn.click()
         result = WebDriverWait(browser, 2).until(
             EC.presence_of_element_located((By.ID, 'result')))
     else:
         result = browser.find_element_by_id('result')
     self.assertEqual(browser.title, 'Result Page')
     result = json.loads(result.text)
     self.assertTrue('profile' in result)
     self.assertTrue('credentials' in result)
     self.assertTrue('displayName' in result['profile'])
     self.assertTrue('accounts' in result['profile'])
Exemple #22
0
    def test_layout_analysis(self):    
        driver = self.driver        

        # Wait for the image window to be present (ensures browser is fully loaded)
        imageWindow = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))

        # Find the layout button on the menu bar and click it.
        self._clickLayoutButton( driver )
        
        # Find the layout analysis button in the submenu and click it.
        analysisLayoutButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[text()='Analysis Layout']")))
        self.assertIsNotNone( analysisLayoutButton, "Could not find layout analysis button in submenu")
        ActionChains(driver).click( analysisLayoutButton).perform()
        
        # Check that there is an Image Window
        imageWindow = driver.find_element_by_xpath("//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")
        self.assertIsNotNone( imageWindow, "Could not find an image window")
        
        # Check that there is a Histogram Window
        histogramWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowHistogram']")))
        self.assertIsNotNone( histogramWindow, "Could not find aCha histogram window")

        # Check that there is a Colormap Window
        colormapWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowColormap']")))
        self.assertIsNotNone( colormapWindow, "Could not find a colormap window")

        # Check that there is an AnimatorWindow
        animatorWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowAnimation']")))
        self.assertIsNotNone( animatorWindow, "Could not find an animator window")
        
        # Check that there are the correct number of Windows
        desktopList = driver.find_elements_by_xpath("//div[@qxclass='qx.ui.window.Desktop']")
        windowCount = len( desktopList )
        print windowCount
        self.assertEqual( windowCount, 4, "Image Layout does not have the correct number of window")
Exemple #23
0
    def has_claimed_mulligan(self):
        """
        Returns True if the account with self.username and self.password
        has claimed its mulligan, false otherwise
        """
        ## navigate to claim mulligan page
        self._get_make_picks_page()
        more = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, "last"))
            )
        more.click()
        button1 = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, "bam-button-primary"))
            )
        buttons = self.browser.find_elements_by_class_name('bam-button-primary')
        buttons[3].click()

        ## Check if we've claimed the mulligan
        mulOption = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, "mulligan-list")) 
            )
        mulOption.click()
        try:
            claimMul = WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, 'claim-mulligan-btn')))
        except TimeoutException:
            return True

        return False
Exemple #24
0
    def __get_team_selection_dropdown(self, **kwargs):
        """
        kwargs --> None
           team: str | team for which we are selecting the dropdown

        """
        ## Extract variables
        team = kwargs['team']

        ## Typecheck
        assert type(team) == str

        ## Necessary team conversions
        team = self.__convert_team(team)

        ## Make sure the player selection dropdown has been dropped
        self._get_player_selection_dropdown()
        selectTeam = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.ID, 'team-name')))
        selectTeam.click()
        time.sleep(3)

        # click on desired team
        team = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, team)))
        team.click()
        time.sleep(3)
Exemple #25
0
    def claim_mulligan(self):
        print "-->Claiming Mulligan for u, p: {0}, {1}\n".format(self.username, self.password)
 
        try: 
            ## navigate to claim mulligan page
            self._get_make_picks_page()
            more = WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, "last"))
                )
            more.click()
            button1 = WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, "bam-button-primary"))
                )
            buttons = self.browser.find_elements_by_class_name('bam-button-primary')
            buttons[3].click()

            ## Claim the mulligan
            mulOption = WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, "mulligan-list")) 
                )
            mulOption.click()
            claimMul = WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.CLASS_NAME, 'claim-mulligan-btn'))
                )
            claimMul.click()
            
            # give it some time, then quit the browser and if necessary, stop the display
            time.sleep(10)
            self.quit_browser()
        except:
            try:
                self.quit_browser()
                raise
            except:
                raise
    def __init__(self,driver):
        super(dailyReportPage,self).__init__(driver)
        #self._driver=driver
        self.work_daily_mine=WebDriverWait(self._driver, 10).until(EC.presence_of_element_located((By.ID, 'com.hecom.sales:id/rb_work_daily_mine')))
        #self.work_daily_subordinate=WebDriverWait(self._driver, 10).until(EC.presence_of_element_located((By.ID, 'com.hecom.sales:id/rb_work_daily_subordinate')))

        self.addreport=WebDriverWait(self._driver, 10).until(EC.presence_of_element_located((By.ID, 'com.hecom.sales:id/iv_top_right')))
Exemple #27
0
def get_results(keyword):
    driver = config.DRIVER
    link = config.SEARCH_LINK
    driver.get(link)
    try:
        WebDriverWait(driver, config.TIMEOUT).until(
            EC.presence_of_element_located((By.ID, "mq"))
        )
    except TimeoutException:
        print u'加载页面失败'
    try:
        element = driver.find_element_by_css_selector('#mq')
        print u'成功找到了搜索框'
        keyword = keyword.decode('utf-8', 'ignore')
        print keyword
        print u'输入关键字', keyword
        for word in keyword:
            print word
            element.send_keys(word)
        element.send_keys(Keys.ENTER)
    except NoSuchElementException:
        print u'没有找到搜索框'
    print u'正在查询该关键字'
    try:
        WebDriverWait(driver, config.TIMEOUT).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, "#J_ItemList div.productImg-wrap"))
        )
    except TimeoutException:
        print u'查询失败'
    html = driver.page_source
    return html
Exemple #28
0
    def _get_make_picks_page(self):
        """
        Logs in to mlb beat the streak site
        """
        ## Are we already on it?
        if self.pageTitles['picks'] in self.browser.title:
            return

        ## Else navigate to the login page
        if not self.pageTitles['login'] in self.browser.title:
            self._get_login_page()

        ## If we were already logged in, then now we are on the picks page
        if self.pageTitles['picks'] in self.browser.title:
            return
        
        # Otherwise, we need to login
        login = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.ID, 'login_email')))
        login.send_keys(self.username)
        pword = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.ID, 'login_password')))
        pword.send_keys(self.password)
        submit = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((By.NAME, 'submit')))
        submit.click()
        time.sleep(3)
        assert self.browser.title == self.pageTitles['picks']
Exemple #29
0
    def test_minimize_restore(self):
        driver = self.driver
        timeout = selectBrowser._getSleep()

        # Find a window capable of loading an image and select the window
        imageWindow = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
        ActionChains(driver).click( imageWindow ).perform()
        time.sleep( timeout )

        # Click the Window button
        windowButton = driver.find_element_by_xpath( "//div[text()='Window']/..")
        ActionChains(driver).click( windowButton ).perform()

        # Look for the minimize button in the submenu.
        minimizeButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div/div[text()='Minimize']/..")))
        ActionChains(driver).click( minimizeButton ).perform()

        # Verify that there is a Restore button on the status bar and no DisplayWindowImage.
        restoreButton = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[contains(text(), 'Restore: CasaImageLoader')]/..")))

        # Restore the window.  Verify the restore button is gone from the status bar and there is a DisplayWindowImage
        ActionChains(driver).click( restoreButton ).perform()

        #Check that the clipping menu item is no longer available
        try:
            restoreLabel = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='qx.ui.toolbar.MenuButton']/div[contains(text(), 'Restore: CasaImageLoader')]")))
            self.assertTrue( False, "Should not be able to locate the restore image loader button")
        except Exception:
            print "Test restore button was successfully removed"
        imageWindow = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//div[@qxclass='skel.widgets.Window.DisplayWindowImage']")))
  def post_submission_thread_update(self, post_text):
    """
    Add Docstring
    """
    #self.login_to_page()
    
    content = urllib2.urlopen(self.submission_thread_url).read()
    soup = BeautifulSoup(content)
    page_links = soup.find('ul', 'b-pagination-list').findAll('a', 'b-pagination-item')
    final_page_number = int(page_links[-1].contents[0])
    final_thread_page_url = '{0}?page={1}'.format(self.submission_thread_url, str(final_page_number))
    print final_thread_page_url
    
    driver = webdriver.Firefox()
    driver.get(self.submission_thread_url)
    
    
    
    login_link = driver.find_element_by_link_text("Login")
    login_link.click()

    #Wait for availability of username field, then enter username, password, and click the login button
    login_name = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, "field-username")))
    login_name.send_keys(self.username)
    login_password = driver.find_element_by_id("field-loginFormPassword")
    login_password.send_keys(self.password)
    login_button = driver.find_element_by_name("login")
    login_button.click()
    
    driver.get(final_thread_page_url)
    
    text_area = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, "field-body")))
    text_area.send_keys(post_text)
Exemple #31
0
#open the coding bat website in browser
browser.get('https://codingbat.com/java')

dirName=".\CodingBatSolution"
if not os.path.exists(dirName):
    os.mkdir(dirName)
    print("Directory " , dirName ,  " Created ")
else:    
    print("Directory " , dirName ,  " already exists")
	
os.chdir(dirName)
root = os.getcwd()


#waiting for the user name box and setting it to the specific username
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.NAME,'uname'))).send_keys(username)

#waiting for the password field and setting it to the entered password
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.NAME,'pw'))).send_keys(pw)

#Wait for the login button and click on it
WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.NAME,'dologin'))).click()

#get the html code of the current page in the browser
problems = browser.page_source

#parse the html using BeautifulSoup
soup = bs4.BeautifulSoup(problems,"lxml")

#select the list of problem categories from the given element
problemCategories = soup.select('div.tabin div:nth-of-type(1)')
Exemple #32
0
def f2(driver):
    global PAGE
    global CC_TEXT
    PAGE = []
    CC_TEXT = []
    total = 0
    locator = (By.XPATH,
               '//td[@id="MoreInfoList1_tdcontent"]/table/tbody/tr[1]/td[2]/a')
    WebDriverWait(driver, 10).until(EC.presence_of_element_located(locator))
    # 第一个等待
    for i in range(1, 5):
        if i != 1:
            mark = driver.find_element_by_xpath(
                '//font[@class="currentpostionfont"]/../font[2]/a[2]/font'
            ).text
            if mark == '标前公示':
                driver.find_element_by_xpath(
                    '//font[@class="currentpostionfont"]/../font[2]/a[2]'
                ).click()
            else:
                driver.find_element_by_xpath(
                    '//font[@class="currentpostionfont"]/../font[2]/a[3]'
                ).click()

            locator = (By.XPATH,
                       '(//font[@class="MoreinfoColor"])[{}]'.format(i))
            WebDriverWait(driver, 10).until(
                EC.presence_of_element_located(locator)).click()
            locator = (By.XPATH, '//tr[@class="TDStylemore"][1]/td[2]/a')
            WebDriverWait(driver,
                          10).until(EC.presence_of_element_located(locator))
            driver.find_element_by_link_text('更多信息').click()
            locator = (
                By.XPATH,
                '//td[@id="MoreInfoList1_tdcontent"]/table/tbody/tr[1]/td[2]/a'
            )
            WebDriverWait(driver,
                          10).until(EC.presence_of_element_located(locator))
        try:
            total_ = driver.find_element_by_xpath(
                '//div[@id="MoreInfoList1_Pager"]/table/tbody/tr/td[1]/font[2]/b'
            ).text
        except:
            total_ = 0
        try:
            c_text = driver.find_element_by_xpath(
                '//font[@class="currentpostionfont"]/../font[2]/a[4]/font'
            ).text.strip()
        except:
            c_text = driver.find_element_by_xpath(
                '//font[@class="currentpostionfont"]/../font[2]/a[3]/font'
            ).text.strip()
        total_ = int(total_)
        PAGE.append(total_)
        CC_TEXT.append(c_text)

        total = total + int(total_)
        total = int(total)

    driver.quit()
    return total

# Browser
path = '/Users/martin/Documents/codingnomads/nlpython/_onwards/click/'
driver = webdriver.Chrome(f"{path}chromedriver")
driver.get('http://newssearch.chinadaily.com.cn/en/search?query=trade%20war')

link_bucket = []  # a bucket to collect all our links
num_pages = 5  # define here how many pages shall be scraped

# get the first click on "NEXT". has a different path than the following ones
first_next_path = "/html[1]/body[1]/div[5]/div[2]/div[5]/div[1]/div[2]/span[1]/a[5]"
next_next_paths = "/html[1]/body[1]/div[5]/div[2]/div[5]/div[1]/div[2]/span[1]/a[6]"

# first time round!
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, first_next_path)))
next_button = driver.find_element_by_xpath(first_next_path)
next_button.click()  # clicking button

for _ in range(num_pages):
    # waiting to find element.
    # this might have to be improved to wait for an element that is
    # only present once all the links on the page are loaded. otherwise
    # the scraper might not fetch all the links on the page
    WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, next_next_paths)))
    next_button = driver.find_element_by_xpath(next_next_paths)
    next_button.click()  # clicking button
    # quick fix to make it more likely that the relevant links are loaded
    # TODO: make sure all links are there before fetching them
    time.sleep(1)
    try:
Exemple #34
0
 def wait_for_page_to_load(self):
     WebDriverWait(self.selenium, self.timeout).until(
         EC.presence_of_element_located((By.CSS_SELECTOR, 'body.loaded')))
Exemple #35
0
 def clear_input_box(self):
     """Clear Input"""
     self.wait.until(
         EC.presence_of_element_located(
             (By.XPATH, '//*[@id="input-id"]'))).clear()
     time.sleep(2)
Exemple #36
0
##### Construct a Browser
browser = webdriver.Chrome(driver_path)

###### get the url
url = "https://accounts.google.com/signin/v2/identifier?continue=https%3A%\
2F%2Fmail.google.com%2Fmail%2F&service=mail&sacu=1&rip=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin"

browser.get(url)

##### Maximize the window
browser.maximize_window()

########## Enter Email Acocount
WebDriverWait(browser, 45).until(
    EC.presence_of_element_located(
        (By.XPATH, '//*[@id="identifierId"]'))).send_keys("your email")

### Selenium hot keys list:
### https://selenium-python.readthedocs.io/api.html?highlight=keys#module-selenium.webdriver.common.keys

##### Click next
WebDriverWait(browser, 45).until(
    EC.presence_of_element_located(
        (By.XPATH, '//*[@id="identifierNext"]/content/span'))).click()

time.sleep(2)

##### Enter the password
WebDriverWait(browser, 45).until(
    EC.presence_of_element_located(
        (By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input'
Exemple #37
0
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

# Replace below path with the absolute path of chromedriver in your PC
driver = webdriver.Chrome('/home/saket/Downloads/chromedriver')

driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)

# Replace 'Friend's Name' with the name of your friend
# or the name of a group
target = '"Friend\'s Name"'

# Replace the below string with your own message
string = "Message sent using Python!!!"

arg = '//span[contains(@title,' + target + ')]'
# Searches The Contact Name
group = wait.until(EC.presence_of_element_located((By.XPATH, arg)))
group.click()
inp = '//div[@class="input"][@dir="auto"][@data-tab="1"]'
input1 = wait.until(EC.presence_of_element_located((By.XPATH, inp)))
for i in range(100):
    # Sends the Message
    input1.send_keys(string + Keys.ENTER)
    time.sleep(1)
Exemple #38
0
def seasonvarByPass(url, maxEps=30, delayz=(2, 0.6)):
	log.info('seasonvar season bypass init\n')
	log.info('url={}, maxEps={}'.format(url, maxEps))
	log.debug('delays used(in seconds) {}'.format(delayz))

	browser = firefoxDriverInit()

	browser.set_window_position(0, 0)
	browser.set_window_size(500, 500)

	try:
		browser.get(url)
		WebDriverWait(browser, 120).until(EC.presence_of_element_located((By.XPATH, '//span[@class="pgs-head"]')))

		log.debug('target loaded')

		#print (browser.current_url)

		time.sleep(delayz[0])

		vods = []
		ep = len(browser.find_elements_by_xpath('//pjsdiv[@style="position: relative; right: 0px; top: 0px; cursor: pointer; height: 50px; overflow: hidden; width: 170px; display: inline-block; line-height: 1.5em; vertical-align: top; white-space: normal;"]'))

		log.debug(ep)

		if ep > maxEps:
			ep = maxEps

			#print ('maxed out, capping to {}'.format(ep))

		ETA = ep*3

		#print ('ETA {}s'.format(ETA))
		log.info('ETA {}s'.format(ETA))
		#print (ep)


		subElem = browser.find_elements_by_xpath('//li[@data-translate="1"]')

		if len(subElem) != 0:
			log.debug('original dub obj found')

			klk(subElem[0], browser)
			log.debug('original dub obj clicked')

		log.debug('{} episodes to extract'.format(ep))
		log.debug('starting episode extract')

		for i in range(ep):
			try:
				elem = browser.find_element_by_xpath('//pjsdiv[@fid="{}" and @style="position: relative; right: 0px; top: 0px; cursor: pointer; height: 50px; overflow: hidden; width: 170px; display: inline-block; line-height: 1.5em; vertical-align: top; white-space: normal;"]'.format(i))
				klk(elem, browser)

				adElem = browser.find_element_by_xpath('//pjsdiv[@id="oframehtmlPlayer"]')

				time.sleep(delayz[1])

				klk(adElem, browser)

				aw = browser.window_handles
				if len(aw) >= 2:
					browser.switch_to_window(aw[1])
					browser.close()
					browser.switch_to_window(aw[0])

				vods.append(getVod(browser))

			except Exception as e:
				log.debug('episode {} failed: {}'.format(i, e))
				vods.append('failed')

		browser.quit()
		log.debug('done')

	except Exception as e:
		browser.quit()

		log.error('seasonvar season bypass failed', exc_info=True)

		return True, None, None

	log.info('seasonvar season bypass complete')

	return False, vods, ep
Exemple #39
0
def animevostBypassEp(url, ep, delayz=(2, 1)):
	log.info('animevost episode bypass init\n')
	log.info('url={}, ep={}'.format(url, ep))
	log.debug('delays used(in seconds) {}'.format(delayz))
	ep2 = ep

	browser = firefoxDriverInit()

	browser.set_window_position(0, 0)
	browser.set_window_size(500, 500)

	try:
		browser.get(url)

		WebDriverWait(browser, 120).until(EC.presence_of_element_located((By.XPATH, '//div[@class="functionPanel"]')))

		log.debug('target loaded')

		time.sleep(delayz[0])

		try:
			name = browser.find_element_by_xpath('//div[@class="shortstoryHead"]/h1').text

			log.debug(name)

			name = name.replace('\n', ' ').rsplit(']')[0].rsplit('[')[1].split(' ')[0].split('-')

			if int(name[0]) <= ep <= int(name[1]):
				pass

			else:
				if int(name[0]) > ep:
					ep = int(name[0])
					#print ('mined out, capping to {}'.format(ep))

				elif int(name[1]) < ep:
					ep = int(name[1])
					#print ('maxed out, capping to {}'.format(ep))
		except Exception as e:
			log.debug('failed to get episode count of the show: {}'.format(e))
			ep = ep2

		epElem = browser.find_element_by_xpath('//div[@id="p{}"]'.format(ep-1))

		log.debug('target episode obj found')

		klk(epElem, browser)
		log.debug('target episode obj clicked')
		time.sleep(delayz[1])

		vod2 = getVod2(browser)

		browser.quit()
		log.debug('done')

	except Exception as e:
		browser.quit()

		log.error('animevost episode bypass failed', exc_info=True)

		return True, None, None

	log.info('animevost episode bypass complete')

	return False, vod2, ep
 def wait_for_element_present(self, by=By.XPATH, value=None, text=None, time_to_wait=10):
     if text is not None:
         value = value % text
     wait = WebDriverWait(self.driver, time_to_wait)
     return wait.until(EC.presence_of_element_located((by, value)))
Exemple #41
0
            f.write(i + '\n')
            print(i)
        f.close()


if __name__ == '__main__':
    try:
        start_date = '20200101'
        end_date = '20200111'
        last_one_day = timedelta(days=1)
        today = datetime.strptime(start_date,'%Y%m%d').date()
        end_date = datetime.strptime(end_date,'%Y%m%d').date()
        current_url = 'http://data.eastmoney.com/hsgt/top10.html'
        while today <= end_date:
            if is_workday(today):
                driver.get(current_url[:-5] + "/" + str(today) + ".html")
                page_load_complete = WAIT.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".titbar > .tit")))
                # print("页面加载完成")
                html = driver.page_source
                soup = BeautifulSoup(html, 'lxml')
                date = soup.select_one(".sitebody > .maincont > .contentBox > .content > .tab1")
                # print(today)
                data_list.append(today.strftime('%Y%m%d'))
                # print(date is not None)
            today = today+last_one_day
        path = get_stock_data_path()
        save_file(path+"/北向买卖A股时间")
    finally:
        driver.quit()

Exemple #42
0
def animevostBypass(url, epRange=None, maxEps=40, delayz=(2, 0.8)):
	log.info('animevost season bypass init\n')
	log.info('url={}, maxEps={}'.format(url, maxEps))
	log.debug('delays used(in seconds) {}'.format(delayz))

	browser = firefoxDriverInit()

	browser.set_window_position(0, 0)
	browser.set_window_size(500, 500)

	try:
		browser.get(url)

		WebDriverWait(browser, 120).until(EC.presence_of_element_located((By.XPATH, '//div[@class="functionPanel"]')))

		log.debug('target loaded')

		time.sleep(delayz[0])

		try:
			name = browser.find_element_by_xpath('//div[@class="shortstoryHead"]/h1').text

			log.debug(name)

			name = [int(i) for i in name.split(']')[0].split('[')[1].split(' ')[0].split('-')]

			if epRange != None:
				if epRange[1] > int(name[1]):
					epRange[1] = int(name[1])

				if epRange[0] < 0:
					epRange[0] = 0

				if epRange[1]-epRange[0] > maxEps:
					epRange = None

			if epRange != None:
				name[0] = epRange[0]
				name[1] = epRange[1]

			if int(name[1]) > maxEps:
				name[1] = maxEps

			if int(name[0]) > 0:
				name[0] -= 1

			ETA = name[1]*1.25

		except Exception as e:
			log.debug('failed to get episode count of the show: {}'.format(e))
			name = (0, 1)
			ETA = -1

		#print ('ETA {}s'.format(ETA))
		log.info('ETA {}s'.format(ETA))

		lolz = []

		log.debug('{} episodes to extract'.format(name[1]))
		log.debug('starting episode extract')

		for i in range(name[0], name[1]):
			try:
				epElem = browser.find_element_by_xpath('//div[@id="p{}"]'.format(i))

				klk(epElem, browser)
				time.sleep(delayz[1])

				lolz.append(getVod2(browser))

			except Exception as e:
				log.debug('episode {} failed: {}'.format(i, e))
				lolz.append('failed')

		browser.quit()
		log.debug('done')

	except Exception as e:
		browser.quit()

		log.error('animevost season bypass failed', exc_info=True)

		return True, None, None

	log.info('animevost season bypass complete')

	return False, lolz, name[1]
Exemple #43
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
Exemple #44
0
def seasonvarByPassEp(url, ep, delayz=(2, 3, 2)):
	log.info('seasonvar episode bypass init\n')
	log.info('url={}, ep={}'.format(url, ep))
	log.debug('delays used(in seconds) {}'.format(delayz))
	ep2 = ep

	browser = firefoxDriverInit()

	browser.set_window_position(0, 0)
	browser.set_window_size(500, 500)

	try:
		browser.get(url)
		WebDriverWait(browser, 120).until(EC.presence_of_element_located((By.XPATH, '//span[@class="pgs-head"]')))

		log.debug('target loaded')

		time.sleep(delayz[0])

		#print (browser.current_url)

		try:
			epLen = len(browser.find_elements_by_xpath('//pjsdiv[@style="position: relative; right: 0px; top: 0px; cursor: pointer; height: 50px; overflow: hidden; width: 170px; display: inline-block; line-height: 1.5em; vertical-align: top; white-space: normal;"]'))


			log.debug(epLen)

			if 1 <= ep <= epLen:
				pass

			else:
				if 1 > ep:
					ep = 1
					#print ('mined out, capping to {}'.format(ep))

				elif epLen < ep:
					ep = epLen
					#print ('maxed out, capping to {}'.format(ep))

		except Exception as e:
			log.debug('failed to get episode count of the show: {}'.format(e))
			ep = ep2

		#print (ep)


		subElem = browser.find_elements_by_xpath('//li[@data-translate="1"]')

		if len(subElem) != 0:
			log.debug('original dub obj found')

			klk(subElem[0], browser)
			log.debug('original dub obj clicked')

		time.sleep(delayz[1])

		elem = browser.find_element_by_xpath('//pjsdiv[@fid="{}" and @style="position: relative; right: 0px; top: 0px; cursor: pointer; height: 50px; overflow: hidden; width: 170px; display: inline-block; line-height: 1.5em; vertical-align: top; white-space: normal;"]'.format(ep-1))

		log.debug('target episode obj found')

		klk(elem, browser)
		klk(elem, browser)
		log.debug('target episode obj clicked')

		time.sleep(delayz[2])

		vod = getVod(browser)

		browser.quit()
		log.debug('done')

	except Exception as e:
		browser.quit()

		log.error('seasonvar episode bypass failed', exc_info=True)

		return True, None, None

	log.info('seasonvar episode bypass complete')

	return False, vod, ep
Exemple #45
0
def msdn_search(question, need_translation, available_len):
    global driver

    rtnString = ''
    try:
        # Search
        print("Searching for: " + question)
        driver.get('https://docs.microsoft.com/en-us/search/?search=' +
                   question + '&category=Documentation&skip=0')
        WebDriverWait(driver, 5).until(
            EC.presence_of_element_located(
                (By.XPATH, '//*[@id="resultCount-header"]/div[1]/h1')))

        # Click the first link
        element = driver.find_element_by_xpath(
            '//*[@id="main"]/div[2]/ol/li[1]/h2/a')
        print("Link found. Requesting contents...")
        element.click()
        WebDriverWait(driver, 5).until(
            EC.presence_of_element_located((By.XPATH, '//*[@id="main"]')))

        # Parse the information
        try:  # Try to get article title
            content_title = driver.find_element_by_tag_name('h1').text
        except:
            content_title = ""
        try:  # Try to get a general description
            content_description = driver.find_element_by_xpath(
                '//*[@id="main"]/p[1]').text
        except:
            content_description = ""
        try:  # Try to get function parameters
            function_syntax = driver.find_element_by_xpath(
                '//*[@id="main"]/pre[1]/code').text
        except:
            function_syntax = ""

        available_len -= len(driver.current_url) + 10
        if content_title != '':
            if need_translation:
                content_title = youdao_translate(content_title, False)
            rtnString += "文档: " + content_title + "\n"
            available_len -= len(content_title) + 5
        if content_description != '':
            if need_translation:
                content_description = youdao_translate(content_description,
                                                       False)
            if len(content_description) > available_len:
                content_description = content_description[0:available_len -
                                                          8] + "...(省略)"
            rtnString += "描述: " + content_description + "\n"
            available_len -= len(content_description) + 5
        if function_syntax != '':
            if available_len > 13:
                if len(function_syntax) > available_len:
                    function_syntax = function_syntax[0:available_len -
                                                      13] + "...(省略)"
                rtnString += "代码:\n" + function_syntax + "\n"
        rtnString += "链接: " + driver.current_url
        print("Contents returned!")
        return rtnString
    except NoSuchElementException:
        print("Link not found!")
        rtnString = "没有找到相关的信息哦!你搜这么骚的东西干嘛?"
    except TimeoutException:
        print("Request timed out!")
        rtnString = "请求超时!大概是因为小水管堵住了吧。"
    except:
        print("Failed to load webpage!")
        rtnString = "加载网页失败!大概冰棍断网了?(那你QQ怎么在线的)"
    return rtnString
Exemple #46
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
Exemple #47
0
 def sendAdMessage(self):
     self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, ".textarea-input")))
     textArea = self.driver.find_element_by_css_selector(".textarea-input")
     textArea.send_keys(self.adText)
Exemple #48
0
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

headless_options = Options()
headless_options.add_argument('--headless')

driver = webdriver.Chrome(options=headless_options)
driver.get('https://www.bbc.co.uk/news')

search_box = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located(
        (By.CSS_SELECTOR, 'input[id="orb-search-q"]')))
#search_box = driver.find_element_by_css_selector('input[id="orb-search-q"]')


ActionChains(driver).move_to_element(search_box).click() \
 .send_keys('Global coronavirus updates').key_down(Keys.ENTER).perform()

top_titles = driver.find_elements_by_css_selector(
    'div[class="css-14rwwjy-Promo ett16tt11"]')

with open('Coronavirus_headlines.txt', 'w') as cor_virus:
    for title in top_titles:
        headline = title.find_element_by_css_selector(
            'p[class="css-1aofmbn-PromoHeadline ett16tt4"]').text
        cor_virus.write('\n')
        cor_virus.write(headline)
Exemple #49
0
 def isChineseSeller(self):
     self.wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, ".a-unordered-list.a-nostyle.a-vertical")))
     sellerInfo = self.driver.find_element_by_css_selector(".a-unordered-list.a-nostyle.a-vertical")
     return sellerInfo.text.find("CN") != -1
def goWebsite_1756718_10001(DictFrmObs, dictfiletorun, scpath, master_path,
                            publication, smid):
    finscname = ""
    strerror = ""
    res = False
    # ----------------------------------------------------------------------------------------------
    publication = publication.lower()
    url = str(DictFrmObs[publication][1])
    mID = str(DictFrmObs[publication][0])
    pubname = str(DictFrmObs[publication][2])
    arr_mID = mID.split(":")
    filenm = dictfiletorun["SaveFileName"]
    parent_el = None

    saveName = arr_mID[0].strip() + "_" + filenm + "_" + datetime.datetime.now().strftime("%Y%m%d") \
               + arr_mID[(len(arr_mID) - 1)].strip()

    # check file at source file folder exist or not
    scpathTemp = scpath + "/" + "Temp_" + datetime.datetime.now().strftime(
        '%Y%m%d_%H%M%S')
    DestinationFile = scpath + "/" + saveName
    SFilename = scpathTemp + "/" + saveName

    if os.path.exists(SFilename):
        os.remove(SFilename)

    if os.path.exists(DestinationFile):
        os.remove(DestinationFile)

    chrome_options = webdriver.ChromeOptions()
    scpathTemp = str(scpathTemp).replace('/', '\\').strip()
    preferences = {
        "directory_upgrade": True,
        "download.default_directory": scpathTemp,
        "plugins.always_open_pdf_externally": True,
        "download.prompt_for_download": False,
        "download.directory_upgrade": True,
        "safebrowsing.enabled": True,
        'profile.default_content_setting_values': {
            'cookies': 2,
            'images': 2,
            'javascript': 2,
            'plugins': 2,
            'popups': 2,
            'geolocation': 2,
            'notifications': 2,
            'auto_select_certificate': 2,
            'fullscreen': 2,
            'mouselock': 2,
            'mixed_script': 2,
            'media_stream': 2,
            'media_stream_mic': 2,
            'media_stream_camera': 2,
            'protocol_handlers': 2,
            'ppapi_broker': 2,
            'automatic_downloads': 2,
            'midi_sysex': 2,
            'push_messaging': 2,
            'ssl_cert_decisions': 2,
            'metro_switch_to_desktop': 2,
            'protected_media_identifier': 2,
            'app_banner': 2,
            'site_engagement': 2,
            'durable_storage': 2
        }
    }
    chrome_options.add_experimental_option("prefs", preferences)
    chrome_options.add_argument("disable-infobars")
    chrome_options.add_argument("--disable-extensions")

    try:
        driver = webdriver.Chrome(chrome_options=chrome_options,
                                  executable_path=master_path +
                                  "/chromedriver.exe")
    except:
        strerror = "Failed - <Webdriver Error>"
        driver.close()
        return finscname, strerror

    driver.get(url)
    WebDriverWait(driver,
                  30).until(EC.presence_of_element_located((By.TAG_NAME, 'a')))
    dnow = datetime.datetime.now()
    anc_txt = 'budget ' + str(dnow.year)

    try:
        try:
            # 1st page
            for el in driver.find_elements_by_tag_name('a'):
                if xt(str(el.get_attribute('innerText'))).strip().find(xt(anc_txt)) >= 0 and \
                        xt(str(el.get_attribute('href'))).strip().find(xt('publication')) >= 0:
                    driver.get((el.get_attribute('href')))
                    # el.click()
                    time.sleep(3)
                    break

            for el in driver.find_elements_by_tag_name('a'):
                if xt(str(el.get_attribute('innerText'))).strip().find(
                        xt("Summary Tables for the Estimates of Appropriations"
                           )) >= 0:
                    # el.click(el.get_attribute('href'))
                    driver.get((el.get_attribute('href')))
                    time.sleep(3)
                    break

            for el in driver.find_elements_by_tag_name('a'):
                if xt(str(el.get_attribute('href'))).strip().find(
                        xt(".pdf")) >= 0:
                    # el.click(el.get_attribute('href'))
                    driver.get((el.get_attribute('href')))
                    time.sleep(3)
                    wait_file_complete(scpathTemp)
                    time.sleep(3)
                    bok = True
                    res = True
                    break

            if bok == True:
                time.sleep(3)
                FileList = glob.glob(scpathTemp + "\*")
                if len(FileList) > 0:
                    LatestFile = max(FileList, key=os.path.getctime)
                    os.rename(LatestFile, SFilename)
                    shutil.move(SFilename, DestinationFile)
                    time.sleep(3)
                    res = True
        except Exception as e:
            strerror = str(e)
            strerror = "Failed - <Unable to Download Source File>"
    except Exception as e:
        strerror = str(e)

    if res == False:
        strerror = "Failed - <Unable to Download Source File>"
    if not os.path.exists(DestinationFile):
        strerror = "Failed - <Unable to Download Source File>"

    driver.close()
    if os.path.exists(scpathTemp):
        shutil.rmtree(scpathTemp)
    return DestinationFile, strerror
Exemple #51
0
 def openGoodPage(self, url):
     print("STEP 1 打开商品页面")
     self.driver.get(url)
     self.wait.until(ec.presence_of_element_located((By.ID, "wishListMainButton-announce")))
     print("商品页面加载完成,检测是否是第三方卖家")
Exemple #52
0
 def getContactBtn(self):
     self.wait.until(ec.presence_of_element_located((By.ID, "seller-contact-button")))
     return self.driver.find_element_by_id("seller-contact-button")
Exemple #53
0
            EC.presence_of_all_elements_located((
                By.CSS_SELECTOR, "#highcharts-" + str(3 * (i - 1)) +
                " > svg > g.highcharts-series-group > g.highcharts-markers.highcharts-series-0.highcharts-tracker > path"
            )))
        jobArray = []
        rateArray = []
        for job in jobs:
            jobArray.append(job.text)
        for path in paths:
            action = ActionChains(webdriver)
            action.move_to_element(path)
            action.move_to_element(path)
            action.perform()
            rate = Wait(webdriver, 5).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, "#highcharts-" + str(3 * (i - 1)) +
                     " > svg > g.highcharts-tooltip > text"))).text
            rateArray.append(rate)

        row.append(logo)
        row.append(name)
        row.append(link)
        row.append(totalRate)
        row.append(category)
        row.append(reviewNums)
        row.append(workingHours)
        row.append(consumeDayOff)
        row.append(jobArray)
        row.append(rateArray)
        print('----------')
        print(row)
Exemple #54
0
 def openSellerPage(self, sellerBtn):
     sellerBtn.click()
     self.wait.until(ec.presence_of_element_located((By.ID, "seller-contact-button")))
Exemple #55
0
 def clc_upload(self, delay=1):
     try:
         WebDriverWait(self.driver, delay).until(EC.presence_of_element_located((DownloadLocators.UPLOAD)))
         self.driver.find_element(*DownloadLocators.UPLOAD).click()
     except (NoSuchElementException, TimeoutException):
         return False
Exemple #56
0
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support import expected_conditions as EC

from app.app import App
import time
from selenium.webdriver.support.ui import WebDriverWait

driver = App.xueqiu()
width = driver.get_window_size()['width']
height = driver.get_window_size()['height']
time.sleep(5)
el1 = WebDriverWait(driver, timeout=10, poll_frequency=0.5).until(EC.presence_of_element_located(locator=('xpath', '//*[@text="我的"][@resource-id="com.xueqiu.android:id/tab_name"]')))
TouchAction(driver).tap(el1).perform()
time.sleep(2)
TouchAction(driver).press(x=int(width/2), y=int(height*4/5)).wait(3000).move_to(x=int(width/2), y=int(height/7)).release().perform()


print("this is test two")
print("this is test three")
print("hahaha")
def scrape():
    driver = False
    try:
        options = Options()
        options.add_argument("--headless")
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')
        #options.headless = True
        driver = webdriver.Chrome(options=options)
        url = "https://www.mohfw.gov.in/"
        driver.get(url)  #we are getting data here
        TIMEOUT = 10
        WebDriverWait(driver, TIMEOUT).until(
            EC.presence_of_element_located((
                By.XPATH,
                "/html/body/div/div/div/section[3]/div/div/div/div/table/tbody"
            )))
        webcontent = driver.page_source
        PySoup = BeautifulSoup(webcontent, 'html.parser')
        print("WebPage Loading is complete !!")
    except TimeoutException:
        print("WebPage Loading took too much time !!")
    finally:
        if driver:
            driver.quit()
    divdata = PySoup.find('div', {'class': 'data-table table-responsive'})
    divdate = divdata.h5.span.text.split(",")[0].split(":")[1].strip()
    format = "%d %B %Y"
    datetimeobj = datetime.strptime(divdate, format).date()

    # table_name = statetable table table-striped or you can directly retrive tbody from the beautifulSoup Object
    mylistoftr = PySoup.find('tbody').find_all(
        'tr')  #it will contain state data

    mytabledata = []
    headings =  ["Sr.No","States/UT","Active Cases","Active Cases Since Yesterday",\
                "Recovered Cases","Recovered Cases Since Yesterday","Deceased Cases","Deceased Cases Since Yesterday"]
    for tr in mylistoftr:
        if isinstance(tr, Tag):
            statedata = [-int(td.text.strip()) \
                        if (td.span != None) and (td.span.get('class') in [['down']]) \
                        else td.text.strip()
                        for td in tr.find_all('td')]
            if 'Total#' in statedata:
                statedata.insert(1, "")
            data = dict(zip(headings, statedata))
            mytabledata.append(data)
    covid19df = pd.DataFrame(mytabledata, columns=headings)

    if not covid19df.index.name == 'Sr.No':
        covid19df.set_index('Sr.No', inplace=True)
    covid19df = covid19df[0:35]
    covid19df.replace("", 0, inplace=True)
    covid19df.replace(np.nan, 0, inplace=True)
    # state_data.replace(['',np.nan], 0,inplace=True)
    covid19df['Date'] = datetimeobj.strftime("%d-%m-%Y")
    covid19df.rename(index={'Total#': 'Total'}, inplace=True)
    cols = [
        colname for colname in covid19df.columns
        if colname not in ['Total', 'States/UT', 'Date']
    ]
    covid19df[cols] = covid19df[cols].astype('int')

    if len(covid19df) == 35:
        return [True, covid19df]
    else:
        return [False, covid19df]
Exemple #58
0
 def catalog_products(self, delay=1):
     try:
         WebDriverWait(self.driver, delay).until(EC.presence_of_element_located((ProductsLocators.PRODUCTS)))
         self.driver.find_element(*ProductsLocators.PRODUCTS).click()
     except (NoSuchElementException, TimeoutException):
         return False
Exemple #59
0
users_bunch = random.randint(6, 15)
# todo: must insert 'sent' column in the table
DB.execute("""SELECT id FROM Schoolboys WHERE 'sent' < 1 LIMIT (?)""",
           (users_bunch))
users_list = DB.fetchall()  # returns a list of tuples from DB.execute
ids_str = ",".join(str(
    tpl[0]
    for tpl in users_list))  # make string from all ids to put in the field

# get random picture or text. random from the length of 'photo_list'
photo_id = photo_list[random.randint(0, len(photo_list) - 1)]  # is string
txt = txt_list[random.randint(0, len(txt_list) - 1)]  # is string

try:
    element = Wait(driver, rnd_time()).until(
        EC.presence_of_element_located((By.ID, "dev_const_user_id")))
finally:
    driver.find_element_by_id('dev_const_user_id').clear()
    time.sleep(rnd_time())
    driver.find_element_by_id('dev_const_user_ids').send_keys(ids_str)
    time.sleep(rnd_time())
    driver.find_element_by_id('dev_const_message').clear()
    time.sleep(rnd_time())
    # should we check what we have - picture or text? and select corresponding 'send'
    # just both for now
    driver.find_element_by_id('dev_const_message').send_keys(txt)
    driver.find_element_by_id('dev_const_attachment').send_keys(photo_id)
    time.sleep(rnd_time())
    driver.find_element_by_id('dev_req_run_btn').click()
    time.sleep(rnd_time())
def wait_element(driver, selector, second = 10):
    return WebDriverWait(driver,second).until(EC.presence_of_element_located((By.CSS_SELECTOR, selector)))