How to use find_text method in SeleniumBase

Best Python code snippet using SeleniumBase

import_engineering_bom.py

Source:import_engineering_bom.py Github

copy

Full Screen

...3import base644import io5from odoo import api, models, fields, _6from odoo.exceptions import UserError7def find_text(node, path, out_type=str, true_condition="TRUE"):8 tag = node.find(path)9 if tag is None:10 return False11 if out_type == bool:12 return tag.text.upper() == true_condition13 if out_type == str:14 return tag.text15 return out_type(tag.text)16class EngBomImport(models.TransientModel):17 _name = 'engineering.bom.import'18 _description = 'Import Engineering BOM'19 data_file = fields.Binary(20 string='BOM Data File',21 required=True,22 help="XML file from AZI-SWCustomProperties")23 filename = fields.Char(24 string="Filename")25 batch_id = fields.Many2one(26 comodel_name='engineering.bom.batch',27 string="Engineering BOM Batch",28 readonly=True,29 required=True,30 ondelete='cascade')31 @api.model32 def default_get(self, fields):33 res = super(EngBomImport, self).default_get(fields)34 res['batch_id'] = self._context.get('active_id')35 return res36 @api.multi37 def action_import(self):38 """Load, extract and write BOM data to batch"""39 product_obj = self.env['product.product']40 comp_obj = self.env['engineering.bom.component']41 adjacency_obj = self.env['engineering.bom.adjacency']42 # Decode the file data43 data = base64.b64decode(self.data_file)44 file_input = io.BytesIO(data)45 # parse xml data46 try:47 tree = etree.parse(file_input)48 root = tree.getroot()49 except Exception:50 raise UserError(_("Not a valid file!"))51 assert root.tag == "bom_scan", "Not a valid file!"52 e_comps = root.findall("./config")53 e_adjacencies = root.findall("./adjacency")54 if not len(e_comps):55 raise UserError(_("No part data found"))56 # clear data57 self.batch_id.adjacency_ids.unlink()58 self.batch_id.comp_ids.unlink()59 self.batch_id.part_diff_ids.unlink()60 self.batch_id.bom_diff_ids.unlink()61 self.batch_id.bom_line_diff_ids.unlink()62 # create component records63 for part in e_comps:64 delimiter = '.'65 eng_code = find_text(part, "./PartNum") or ""66 eng_rev = find_text(part, "./Revision") or '-0'67 default_code = "{}{}{}".format(eng_code, delimiter, eng_rev)68 values = {69 'batch_id': self.batch_id.id,70 'name': default_code,71 'filename': find_text(part, "./filename", str),72 'config_name': find_text(part, "./configname", str),73 'image': find_text(part, "./Image", str),74 'part_num': find_text(part, "./PartNum", str),75 'part_rev': find_text(part, "./Revision", str),76 'description': find_text(part, "./Description", str),77 'material_spec': find_text(part, "./Material", str),78 'material_pn': find_text(part, "./MaterialPn", str),79 'rm_qty': find_text(part, "./ChildQty", float),80 'route_template_name': find_text(part, "./RouteTemplate", str),81 'part_type': find_text(part, "./Type", str),82 'make': find_text(part, "./Make", str),83 'coating': find_text(part, "./Coating", str),84 'finish': find_text(part, "./Finish", str),85 'uom': find_text(part, "./Uom", str),86 'alt_qty': find_text(part, "./AltQty", float),87 'cutting_length_outer': find_text(part, "./CuttingLengthOuter", float),88 'cutting_length_inner': find_text(part, "./CuttingLengthInner", float),89 'cut_out_count': find_text(part, "./CutOutCount", int),90 'bend_count': find_text(part, "./BendCount", int),91 }92 comp_obj.create(values)93 # create adjacency records94 for rel in e_adjacencies:95 domain = [96 ('batch_id', '=', self.batch_id.id),97 ('filename', '=', find_text(rel, "./pname")),98 ('config_name', '=', find_text(rel, "./pconfig")),99 ]100 parent_part = self.batch_id.comp_ids.search(domain)101 domain = [102 ('batch_id', '=', self.batch_id.id),103 ('filename', '=', find_text(rel, "./cname")),104 ('config_name', '=', find_text(rel, "./cconfig")),105 ]106 child_part = self.batch_id.comp_ids.search(domain)107 values = {108 'batch_id': self.batch_id.id,109 'parent_comp_id': parent_part.id,110 'child_comp_id': child_part.id,111 'count': find_text(rel, "./adjcount", int)112 }113 adjacency_obj.create(values)114 self.batch_id.state = 'imported'...

Full Screen

Full Screen

ube_civic_facility.py

Source:ube_civic_facility.py Github

copy

Full Screen

...41 db.execute(create_sql)42 records = []43 for child in root.iter('ube_civic_facility'):44 records.append((child.get("id"),45 xml.find_text(child, "label"),46 xml.find_text(child, "category"),47 xml.find_float(child, "latitude"),48 xml.find_float(child, "longlatitude"),49 xml.find_text(child, "postalCode"),50 xml.find_text(child, "address"),51 xml.find_text(child, "phone"),52 xml.find_text(child, "fax"),53 xml.find_text(child, "email"),54 xml.find_text(child, "startTime"),55 xml.find_text(child, "endTime"),56 xml.find_text(child, "timeNotes"),57 xml.find_text(child, "weekClosureday"),58 xml.find_text(child, "closureday"),59 xml.find_text(child, "closuredayNotes"),60 xml.find_text(child, "parking"),61 xml.find_text(child, "parkingFee"),62 xml.find_text(child, "disabledToilet"),63 xml.find_text(child, "reservation"),64 xml.find_text(child, "homepage"),65 xml.find_text(child, "depiction"),66 xml.find_text(child, "depiction")67 ))68 sql = """69 INSERT INTO civic_facility70 (id, name, category, latitude, longitude, postal_code, address,71 phone, fax, email, start_time, end_time, time_notes, week_closure_day,72 closure_day, closure_day_notes, parking, parking_fee, disabled_toilet,73 reservation, homepage, depiction, description) 74 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)75 """76 db.executemany(sql, records)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1#!/usr/bin/env python32# =======================================3# = YT description find + replace =4# = https://twitter.com/telepathics =5# =======================================6# -*- coding: utf-8 -*-7import os8import google_auth_oauthlib.flow9import googleapiclient.discovery10import googleapiclient.errors11scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]12# Disable OAuthlib's HTTPS verification when running locally.13# *DO NOT* leave this option enabled in production.14os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"15api_service_name = "youtube"16api_version = "v3"17client_secrets_file = "oauth_client.json"18new_line = "\n- - - - - -\n"19class YouTubeHandler(object):20 def __init__(self):21 # Get credentials and create an API client22 flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)23 credentials = flow.run_console()24 self.yt = googleapiclient.discovery.build(api_service_name, api_version, credentials=credentials)25 self.channel_info = self.get_channel_info()26 def get_channel_info(self):27 request = self.yt.channels().list(28 part="snippet,contentDetails,statistics",29 mine=True30 )31 return request.execute()32 def get_playlist_videos(self, next_page_token=None):33 upload_playlist = self.channel_info["items"][0]["contentDetails"]["relatedPlaylists"]["uploads"]34 request = self.yt.playlistItems().list(35 part="snippet",36 playlistId=upload_playlist,37 maxResults=50,38 pageToken=next_page_token39 )40 return request.execute()41 def desc_find_replace(self, find_text, replace_text):42 response = self.get_playlist_videos()43 while ("nextPageToken" in response):44 for item in response["items"]:45 if find_text in item["snippet"]["description"]:46 self.replace_video_description(item["snippet"], find_text, replace_text)47 response = self.get_playlist_videos(response["nextPageToken"])48 def replace_video_description(self, snippet, find_text, replace_text):49 request = self.yt.videos().update(50 part="snippet",51 body={52 "id": snippet["resourceId"]["videoId"],53 "snippet": {54 "title": snippet["title"],55 "categoryId": "24",56 "defaultLanguage": "en",57 "description": snippet["description"].replace(find_text, replace_text)58 }59 }60 )61 return request.execute()62def menu():63 print(new_line)64 find_text = input("Find: ")65 print("")66 replace_text = input("Replace: ")67 print(new_line)68 yt = YouTubeHandler()69 yt.desc_find_replace(find_text, replace_text)70 print(new_line)71 print("Done! thanks.")72def main():73 running = True74 while running:75 running = menu()76if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful