def keyboard_enter(self, selector): """ 模拟键盘点击回车键 :param selector: :return: """ self._web_driver_wait(selector).send_keys(Keys().ENTER)
def get_app_id(self): log_in_mail, log_in_pass = self.enter_account_credentials() chrome_options = Options() chrome_options.add_argument("--headless") # web browser without GUI driver = webdriver.Chrome(options=chrome_options) driver.get("https://openexchangerates.org/account/app-ids") email_in = driver.find_element_by_name('email') email_in.send_keys(log_in_mail) time.sleep(2) pass_in = driver.find_element_by_name('pwd') pass_in.send_keys(log_in_pass) time.sleep(1) keys = Keys() pass_in.send_keys(keys.RETURN) time.sleep(1) data = driver.page_source soup = BeautifulSoup(data, 'html.parser') locator = 'input#app-id-126408' app_id = soup.select_one(locator).attrs['value'] return app_id
def group_members_page(browser, group_url): actions = webdriver.ActionChains(browser) browser.get(group_url) keys = Keys() actions.send_keys(keys.ESCAPE) actions.perform()
def capture_gslide(chromedriver_path, gslide_url, max_page_no, save_folder=''): """ take screenshots of Google Slide max_page_no: int """ # avoid SessionNotCreatedException driver = webdriver.Chrome(ChromeDriverManager().install()) driver.implicitly_wait(10) driver.get(gslide_url) time.sleep(3) actions = ActionChains(driver) actions.send_keys(Keys.END) actions.perform() time.sleep(3) # TODO: # get the number of slides ← different btwn each slide # contents = driver.find_elements_by_xpath('.//*[@id="filmstrip"]') # lst = [i.text for i in contents][0].split('\n') # lst = [int(i) for i in lst if re.match(r'[0-9]+', i)] # max_page_no = max(lst) # print('the number of slides: ', max_page_no) # time.sleep(3) # click on Present button and start Present from 1st slide # present_pulldown = driver.find_element_by_xpath('.//*[@id="punch-start-presentation-right"]') # present_pulldown.click() # time.sleep(3) # start the presentation keys = Keys() actions = ActionChains(driver) actions.send_keys(keys.COMMAND + keys.SHIFT + keys.ENTER) actions.key_down(keys.SHIFT).key_down(keys.COMMAND).send_keys(keys.ENTER) actions.perform() time.sleep(8) # move to next page until the end # pressing PAGE_DOWN or ENTER seems not to work actions = ActionChains(driver) actions.click() counter = 1 while counter <= int(max_page_no): fname = '{}.png'.format(str(counter).zfill(2)) save_dir = os.path.join(save_folder, fname) driver.save_screenshot(save_dir) print('Page ' + str(counter) + ' was captured.') actions.perform() counter += 1 time.sleep(2) print('DONE')
def on_report(report, conn): keys = list() updates = list() for joystick in report.joystick: if abs(joystick.info.mean) > threshold: d = joy_to_dir[joystick.axis][copysign(1, joystick.info.mean)] keys.append(d) update = progress( "JOYSTICK", joystick.axis, min(0.999, abs(joystick.info.mean / threshold)) ) else: update = progress("JOYSTICK", joystick.axis, 0) updates.append(update) for update in updates: conn.send(update) for key in keys: print("SENDING KEYPRESS:", key) game_elem.send_keys(Keys().__getattribute__(key))
def vehicle_enum(req): q = req #image = Image.open('download.jpeg', mode='r') #image_to_text = pytesseract.image_to_string(image, lang='eng') #text = '' #text=image_to_text #text1=str(text) #q=text1 class Bot: def __init__(self, number): self.number = number self.bot = webdriver.Firefox() def login(self): bot = self.bot bot.get('https://rtovehicle.info/index.php') time.sleep(2) search = bot.find_element_by_id('vehiclenum') search.send_keys(self.number) clicker = bot.find_element_by_id('searchB') clicker.click() time.sleep(3) bot.execute_script("window.scrollTo(0, 400)") bot.save_screenshot("rto.png") def img_text(self): pytesseract.pytesseract.tesseract_cmd = r"tesseract" image = Image.open('rto.png') image_to_text = pytesseract.image_to_string(image, lang='eng') text = '' text = image_to_text text1 = str(text) #print(text) D = ModernStructures.makedf(text1) #print(D) global s s = D os.system("pkill -f firefox") quantin = Bot(q) quantin.login() key = Keys() quantin.img_text() from sqlalchemy import create_engine import pymysql import numpy as np import pandas as pd tableName = "RC" dataFrame = s dataFrame = dataFrame.T dataFrame.columns = [ 'Name', 'Vehicle_name', 'Regestration_no', 'Date', 'Time' ] dataFrame.drop(labels=None, axis=0, index=0, columns=None, level=None, inplace=True, errors='raise') dataFrame.reset_index(drop=True, inplace=True) dataFrame.to_string(index=False) print(dataFrame) sqlEngine = create_engine( 'mysql+pymysql://root:[email protected]/final_year', pool_recycle=3600) dbConnection = sqlEngine.connect() try: frame = dataFrame.to_sql(tableName, dbConnection, index=False, if_exists='append') except ValueError as vx: print(vx) except Exception as ex: print(ex) else: print("Inserted data to %s Successfully." % tableName) finally: dbConnection.close()
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time driver = None try: cpath = '/usr/local/bin/chromedriver' driver = webdriver.Chrome(cpath) driver.get('https://google.com') search_element = driver.find_element_by_name('q') search_element.send_keys('blue heeler puppies') search_element.send_keys(Keys().RETURN) driver.save_screenshot('heelers.png') finally: if driver is not None: driver.close()
# coding=utf-8 # author:dn_eric(qq:2384363842) # 动脑学院pythonVip课程 # 创建于: 2018/1/31 15:17 """ Keys()类提供了键盘上几乎所有按键的方法。 前面了解到, send_keys()方法可以用来模拟键盘输入, 除此 之外, 我们还可以用它来输入键盘上的按键, 甚至是组合键, 如 Ctrl+A、 Ctrl+C 等。 """ import time from selenium import webdriver # 引入 Keys 模块 from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() driver.get("http://www.baidu.com") # 输入框输入内容 driver.find_element_by_id("kw").send_keys("动脑学员") time.sleep(3) # 删除输入错误的一个员 driver.find_element_by_id("kw").send_keys(Keys.BACK_SPACE) time.sleep(3) # 输入“院” driver.find_element_by_id("kw").send_keys("院") time.sleep(3) # ctrl+a 全选输入框内容 driver.find_element_by_id("kw").send_keys(Keys.CONTROL, 'a') time.sleep(3) # ctrl+x 剪切输入框内容 driver.find_element_by_id("kw").send_keys(Keys.CONTROL, 'x')
def keys(self): return Keys()