Selenium Python Notes

You might also like

Download as pdf
Download as pdf
You are on page 1of 57
wT www rw rwrww ww Sani — Peadhy Vardar, ~~ We driver § One | the Gmpon ent th Selenium ~y web Asien fs Module | ewhich Gontawns «Fire fox browser —> Firefox () +» Chrome brwr —> Chrome () bowser —? Cpe) , e | te rammy Tp > web div» 15 an [Ag] Capptiation Pregremming “i” et Pace Tals (oid wide He ry Setup € ComFiqure [alebdriver . Pay charm « Pre —vequisittes "python : prgthawn © Web browser Specific Drivers * Chrome * Eoge- & Firefox * Safari 1. open web browser [chrome [eter | te] open URL (https: /f ang tan om] provide Email ( adm gra cor] provide pnmord { aden e) on Login yA oF Pash beard prge [ y clic os fo = Capture ttle eo st Close browser Archaal tJ 4 Yerity Uth of page : “Dathboart [ engthing [expe Equal i Not Equy’ wv uv fass Fadl Text re Donn DDN HHH POReDNO TT DD pond CODE Peery Selenium import Webdatver Fron Selestum . Webdaiver Chrome: Soultce. import Service > from Selenium « aia ‘import... By Uwe bLSOKHKYCYYYYYYVHYLYV UY b&b Bb Coavice _ Obfect = = Seuice [ve: Noses oser Nosives\h chrome: ex’) wal ea = Webdotver « Chrome Gsvite = Bae obj) dotver eb len [web ben datver qet (i Link of we”) Af appli | datver . find element ( by. NAME), “ase Us/nine”). Sere Heys (vse) dviver . fing. element (% LTD y “tit pernont”), Send Heys Cr) “ bintesce”). Click daivey . find - element (ed Mag ) 4 actual | expected defver. title: » actual title = Hitle = “ ove expected ' & ex(ected— title « ie actual tite = me (ot po y print (“Test fala”) daiver. close () ly We Can identi Uaxiouws Elements on the [webp Lrg “Locators” Ly Locaters are Adldresses that identity a Web clernent —— = “naa Une vsti the Page: ly che, are 4 ‘ ade ae | t Dae * Linys text / partial Link test__ Co bay ae Closs name ow 0 x Tagname _- > css Selector ¢ « 4 ond Ip ; 1 ag and class nt x Taq ‘and Altvibate % Teg class and attri ble! a : 8 “et x Absolute Xpalh | é — x + Relative path ies ———— oe 4 * & La = link » href. = hyp Imax Reperence Linpat = dext ” ), Send begs ('xxx") > daiver. Pind_element (By ‘Ip, "xe Feel ; > Linpat class = "seaveh” type = nqext, He 1X Name © scarce” » Placchedier= “820” yale aatte mplele = “ore > > > daiver + Name 5 "XxX ) Lelkcwd) Find element (ey HIME Lins = sl usm Test: | partol bing Test ; Link TEST 5 "pegitex') click C) diver . find - element (84: L_Ln test ; “Req ") “clca() datver . Pind- element tine tot ale have Mention, Tool vale garkiak Link at = Gut Haw am ge amin valur Of ctinbule S\iders = dvives. Find elements) (By. Class NAME, " home) Print (Len ( sitders) Mp 4 Wome: wut. ide “home slik) Style = “wax > a [eeu chs a Mheme sua”, Styles 7 1 Shite 7 lings = diver, find element) (By “Tag_Name , “a”) He) (Bg IAG-NAME , Print (len (links) Tag Gid => tag HE Value oF Td e Tay & Claes => tagname » Value of Class Lbsibuke = Valu © Tag § alintlere ptagname: [4 | og mn attrib, tagrome « Valuz of eas [ibd uh | | Ip E nd_el erent (ey. C9$-SELECTOR , " iptetbendi!’) datver. Ff : 4 SendMieys ( XXX x”) Tay ‘Tag € class Ll Cs5- SELECTOR , "Tnput » inpattext/ daver. find _element (6, ’ ) v Send Heys (x xx 7) % ater be a wp, a a CS 9-SELECTOA , ao free = emf ‘cs : daiver . find_ element (84. Sad -top COHN) (ER) |Taq § aitvibute ta4 g class attnbute ot = ati topat igattox daiver . find element (84 + CS$_SELECTOR , send Mags CX XX” arrnielt Eo. oe plus : [pou RX \ncane , Ye have Same Tee 1 KXX . y pouwerd AX Ye cm azn 8 1 Galetor hab Ly Xpath fs depfned as "XML path” . Find ry Element)” La te te fipin Lage lg ny Sos ° XML path expression | ne Using the Location Af Omg element f ‘to _pind Ly. Xpath fs el object Meds] on Webpage ava, Staucture Doctype ° html HTML : HEAD : Dom | ; ae 2 a Bopy Tent Bor we “Mybh” a Lite ) _cticn O EPUUOOUOwUe 2 Contains [starb wit ’ uz Sot ; [td s. Stop I * (contains (@ | + |X (@ ide stat |*(@ 4 see) IP [stats cot (@id sd] 4Confams int! ot dviver . find element (sy XPATH, iat (eu, vn) dp starts -wi th driver. find element (sy. XpaTH, “Yr “Ti -with (@rame., Sf 4 Text Ahaiver, find element ee (+4: xpath, “I [div i ‘ctr J) clionc) Pi ik kSa Dn oO IP [aveibute = =a : Followrg - sibiling | PAUSE From Current ord =" Casa i als of Grtent o Traverse all_child_clemedl child ++ tagname- . child hee a bg : glement oh Cavrent Ips [atoibre ‘value |] : Parent Traverse ee pene = It e fincestor Traverse ol cea sine (=| Ir [acter isle | | pent , Parent et) Of Carat 6 oe — es a cot e Descendant Thovete st dase 6 ae Us Later = ca (childnar , grad de | 4 escent lane ye Ly pat titond Tag oe ba ° Following Paws elt sd [p> [attat bole = on | | ED Current hem! ee Tagen curve tq [oan D sity nb : Trevraer all modes that Gomes’ | M* fattatbute = "value | 7 *Heceding (bajo) he Carnet Hem! tp. | precedrig rs tagnome onl tas, {if Current herr bag [attic Preceding - Travase From) Gunent Hf! Tag, ea fp "ali ; ‘pute Html tag. | ‘vee! [pre 1 Sibtingy bo 2 Presi fp Loss : Xpath Axes 7 {cote} fro — Selenium ‘import Webdaiver, . Bi finey Selenium’ s Webhiver « Common + byinpat G webdaver + Chime. Sewice import Sewhee from Selenium « Suwe_objet = Sewice (ec \\user \\ chromedaives exe) dalven = Webdiver - Chrome (ceruite 2 Seasice_obfect) tive. get ( * ftps : money _ tddif. 07? pains’) text_ms4q 2 datver. find.clement (2.x¢n78 5 Ma Ceomains (textl) *Tpdia “Tourism by] | self a”) a Text Print (test-msq) |4p-Ind ia Burism Da | [fees] text_meq = dalver . Sina element (y. XpaTH "Ya (Lents Cert), Print ( tert -msq)) fp: Undén Tarim De child < defen. find elements (By Xpn oe Fonts (enc "Fnalta Tour’sm Da ) ae) > Print (Len (child) sep 5 zy) text_msq = diver. find - element é. Lapert, "Ja (Contains Hea "Pndig Toots a’) oe 8 em * Paine (text meq) Of: Tndia Tourism Da fey stor noes + O20 B 285.tr0 9565 datver : find. elements, Dscnaat = = 'Indta Fourewm on”) Wee ant : Prine (Len (Descontent Olp: te Es : Lows (text élemenls bg XPATH 5 Me ite : dry. f04- NW ancestor 14 | Fotow' in Follow 4), dia Tout Da Print ( Len (Fellow m4) Jp. 5055 : | follow bg Abivs fa. telby par , "Ma (totems (ews | “Inctia ours Da "SY fenesto nda Holowrg- sibig = Paint. (Len (followrng sibleng) | fp: 618 | \#t Preced i ; | Preceding = daluer. find itil XpATH te fans ; | Paint é len (preceding ) | o ae) daives . find elemeds, (iy er “Ma fle peced mg si bl = Stile 3 5 Pri Clon (preci st) Of? \544) Driver. close () 1. Appl catton Commands 2. Conditional Commande > Te ners ( recens Throvgh “Diva” be geo) wat) ap * ‘the application UBL UBL [= tile — to Capture the (iitte) Bitle) Current Web pai ds ' * Curvent_uvl - £0 Capture the Grrent Us) web page Source Code °F Page . Page. Saude -- bol Caphie | [ode from Selenium, fmport Webdrbur from Gelenfum . webdsiver . commen - buy import By Drom Selenium» Webdriven + Cheome x Gesstoes Import Seavice (‘c fh user |] Chrome dai ver. exe *) Service -objeet) a) ) . , Seavice object = Cervice driv, — webdriver, Chrome (‘service Orange frm live Aviv gt " http’ Il epen Suxedemo Paint ( detver, tte ) | lp: Ff ORANGE OPM Paint ( doiver - Currntv1!) ole: betas: [orange Gomme hem ve | print (aaiver « pye-seree) oh: page Source details > Conditional Commands {cess Through “Web élemuee | ~wTon * era ° is_displayed ¢) Returns “the boolean Values. « fo_ enabled C) Selected () > it fs USed For Radio buttons [checkboxes | = } diver « get ( “bbe: demo. hepeommens «Com Inet’) 15 displayed 4 is —enabled «= dain fr: emert. (24-0009, “Minn (pla oor = ‘Search ste a Point ( dlisplag states, seach box » 1s — dteploged €) print (“enabled status.” , Seaveh box « is-enabled () ) Op 1 diSploy Stats + Thue Crabled Status > Trac Seaych bo HE Io_selected tale radiobulton = driven ra) (oy. xpar, "Ip fem y Ferma Aadio button - Anis . lish dhe &y Xpa te s Input =) Paint C Defaut Parameters - male — *adtobutton .45 selected 0) eeu. S Paint (" ‘male nadio * 9 pane (“female rata :”, Ema nei selected ©) UO * Olp:- Default parameten male nod False Female hadio » False com a rem « mal_ radtobutten . click C) Patnt iG Aber CLicserng, the male”) 7 nadao bultem , ¥5, Jeelectedt) ) wow > print (“male radios» | prin (" Fema racio 2) Female Sait buttén,'s setectede)) ? — top Aber chiding the “ae ome padko : True female radio’ Falte “FS © Femle— Aadivbullon . click) Paint i Lape Clictorng female ) onal sadiobutton .15.Selected C)) Print (“male findin ?) print (Female Adios vg, Female . Fe “male nate button, fs -SekctedC)) : , _———————————— apter click male dado > False Female radi | + Tue | lp - | > Browser Sone { Acca ‘thaoushh Darr oO close C ) - Close Res svg") bransen Wd buiadow [where diver i Feused | [Futile browser windaos [ahi wilt (Hl) the Proc + quit C)- Close we Closa Fieley opto cove | x : Poxente cau + Here Browa (parent) @ Keeps the > 3rou) is d-viver , Close Q beef Chi, bres. dviven , quit C) 4 t ob cath bohale pas and fl : Kill the Pres x Navigon Grmentt (ea Timay “on « back) » forward () ° ath sesh (ap daties get (‘theepe + [asow- Smapdeal ant) C heeps: |] www, omecon, fom pd driver get datver» bach©) Snapdead daiver + forward l) ae amateon datua + Aegrah () # peloads page [onwiow daiye » qui€l) watt oom mamas C gynchaont zation J problem eNO iret ware ~ C20) sleep (ume) ~> Python (Re «time. hormone Off Sexipt is ve - 3) xf The clement fs mot _auilable ott vo oe sale enemboned , stil) Chere fs chance Oh Erypection . a lemplict Wait datver . implicitly - watt (10) | Adwantayers : | T | Single statement be aeduced » [if the cement fs aniles 2, Performance will e& woth m_the_time vit proceed to xCaute Forth Statements Dis Advamtages Ht 4 he element 1S Grok) Available wtlhin, the me || gut there 4 Chance of _gethng reno Exception from Selemarrs ‘mpolt Weodsiver Lio Selenium « wedi « Common» bayimprt “ fyorn Sebersum Webdatvy « Chrome, Sauce impwrty Sewtce Seautce_ Object = Seavtce C "closer I] ehyorme datves sexe’) div, = vebtrivs. Chime (Seautce = Sewice_obyed) datvey . implicit watt (10) datver . ae & https : awe. a ) datvey . maximize _wovndow C ) Seonch = date «prtd_element (By.NAME , "q”) Search + Send - Heys ie scene) : ; Search. Subenit LD 7 dateew x find element (oy.XPATH y" Who [tet = “ScteronJ ). clex 0) Ge Explicte Wlait bed on Condition” f | x Enpiicit Malact orks f pannel x More epyetinly Wonks Dis - Aobvan barges Mai + feel Some diye Tro Selenium fmport Webdriven | from Selbmturn « Webdatver « Comrmerns by import Og | from Selenfam « webdAiver « Chreree . Saice ingore Sauk @ from Selenium » Welpdaiver + Support « wait’ Smport Web Dotra lad Selenium - webdniver « Support «(Ont Inport Web Derr hiat ‘he Henin oie Ser ooo Sewtce object = Sewtce (‘c:lluser | chname dover ,exe’) doive, < Webdaiver . Chivme (Suwice = Service object) ee eee em ywait 2 WebDviverhlait ( driver, 10% Pot-frequenty = 25°" . igre enpections « Ercpton) daiven . at ( https : [Juss google m/) Vrgnon Search = duives . ind element (By. Name "4D Seatith . SendKeys (“Selenium”) Search . Submit C) | bey = MyWail « Until (Ee. Presen de clement laste! +e | (Co4.x0 "Iho (textO= Selenium’) S)) | Seonch link « cick C) | diver. get (“https: /[itera ga + 4zare websites d] 1. Select the | gpeifc Check box) deatven . Pird_elenent (248TH, fd} [fabe £19 ffnpat £1)". 1 de Gina ome Element ® Monde 7 "g. Select the | Mutipl Check box! "Checkbox = daiver, Find_clements (ey xpath " Hpet ote: “Checkbox and Contains (ei, “ay')) ° Paint (len Ccheckbo ¥) Approach). for 1 in ange (ten (chetsbor)) checkbox (1) - click): i lle oe P . Apereath :2 : Tesany « lene dey Ww Sov 3 | Checkbox : + Thursdeuy (OY 4. click 0) + Prldey TA . Sabre a fan 3. checking Muttiple box with Choice fo 1 Checkbox + weehdags = » t_atbatbate (“Td”) ie weendays = = "Monday o weerdays = "Sundey ”: wonsdog | prdoy SJ V. cli® ©) thon tna sharcdy Baburdanl Poy KO Yange (len (checkbox) 2, len (checkbox) : chectibor [iJ . clte4O) 2. (Ce aatithas 9p elrtinle — BOS SEeting pes Yonge (5,1) > &7 fos ema et SIE 5. Select boxes | for i in Tamge (len (checkbox) tt fee : Monday fy Checkbox [1]. clic C) Tuadey ay 6 dear aly Check boX yy appowns. 6 fos th check box ! ” 4. to selected QO: ei 4, cKO) |, Internal Mints 2. External link which dosn't have Target page greater Than, 400 z= 400 Le sO Cqe04) 4, baoken link + '+ clicK om lisay, [tatewmal ] [demo -mopcorn mee com|) driven . get ("Ines Lt [fn texte dotver . fund element (By Laity ‘Digital Doone s”) Lcltes ¢ 1 pe partial Lint bere i, daiva .. find_ elem unt (ey. Panriar. Lins. TEX, Digital”) eb op FP ‘6 Find all Uinns on the Pose) ( external] | Links = daiver + Find elemenbs (® cTageName, “a” 4 2 Paint ( len Clinks ( ) ofp: HAWS ° mama of Urn for ‘1 fn links + eee Paint Gi. text) * Broken links gee eoilinls, ae dotver . get (." heeps: www dead Wor cy om”) desive, . maximize — wrndow() drive . Pmd- elernents (by Tag _Name , “a” a\\ Links = Paint (len C all Uaks ) Count = O fox ¢ in all Links : uae at get atibte Other") tay ‘ : csesponse = “vequests - head Coa) expect : None | ig TESPOE - Stabis-code > = 400 Patt (ua 5 “bwten Winks”) Count = +. else « » Print (uri, “Uatid Uns”) Print (“broken inns ”y Count) Find_Element vk find_Elements » Difference between “find element ” g “find elements Catv» get. (https deme mapconmere on] ‘) Find element () > Beberns Single lebelement ” “te Locater matching coith [ping] webelement ee ot . —"" element = datver. find_ clement (8 XPATH 5 "Winpat [fe id = “Small - Searchterms | f (“neo”) # Aree with Wwebelement eS 2. Locater ‘match! | yeweaaie a ing element. (84: 800TH 3" IY [class = Toota’] Ila") / first Unw fron the Booka 3 Sitemap’ Print (element - text) Hprints FNo Such Element Erepin ——— (not) available then throw ee dotven . find ~_ element (04. pam, 4 Jaty (@toyf login — element = "Login. element « cin) # NoSuch Element ExxcepHon t Found element. Send_h Element = daiver.f 1%. Element find_elements() - "Beturens Muttiple lebelem ents. \. Locater ‘matching Single Single = elements (bg. XpaTH » " [input [e id - webelement ———_ elements = dove - " Small - Search tenes J) Print (Len (elements) FE find_clemonts qu . Webeloment elements [0]. Send_heys ( “Apple”) vn . Locater mnatching with Muttiple web element elements = daives . find elements (ty. XPATH ‘ "Wfarv [@ cess : "Footer ‘JIfa” Paint Clem (elements) 23. webelements Prine, ((elemerts [a] .text)) for 2 fy elements + o mama of +23 el Print (7. text) we * cron, 4. Element No Ava Avoilable : eS clemnts. = Giwn . fund-elements (Bq. LINK-TEXTs "log ) Print (len (elementi)) +H fim Ko] iy List Buty dosn't que Abo wely Clemente found” ee text vg gee-attribate * Snes Lext op the element «text —> Reuse imme ee Cony_attsib: te) . get - attribute Os Returns (Values) pomp st web element en bute (vale) atta bt oa) yee - atta dssiver . gee C “https [admin demo «ropes find element (oy. XPATH, Mogae [@ Pn “admin @ gourstore Corn”. ae as Exe | et ye’) hinece”) Oo Wea wwry enmailbox = datver « oe email box . Clear() . ermaitbor. Senc-Kegs a ‘aheaag Oaraik. con) uw > Parnt (* vewat tat, emailbon- text) » f i ’ et altvibale®, ) Sanarlbox et_attat bute Cvalue’) : Pint ( aa 4 “ fc Zingut id= of nome» “XYZ “emo t Zing : text 2 fext , Has nlo inn ofp ~ your of tot * = (AF Becanye Tex sulk io abcde} Ogmrail- am | f button = Adve, fmna- element (sy XAT, Uo [ery = * gulomil Paint (“‘rusult of tet , Y Luton, text) Print (moult % queatt) luton ck. aurtbute(vab™!), oh popu 95 Tor Login (a Uden cont-ns ee re vam, Webdeiver + Support - Select ‘mport’ Select Som Seleni Jfwe . opencart. Com| fndex host”) datver. act (' https » Select (datver . Find — element (64. XPATH, chop element = = “IIselected (@ fd Bupitch — to - Frome (a of the Frame) | > Butch_ to. frame (Webelernent) gu > Switch to. frame (0) > Sultth to. depaull_Content ip) [eodel dviver. qee (ths pou. Sctiton dey [Selenium [doa /apr » drive, . maximize - window () 4% Frame. switch —to- Frame (" Rachage Ls Fiame”) fw af The Frome ——_——————— dais . pas, Wod_element (By. LInw Tent, Ong. 9 “Sclentan?) «lil | 4 Peng? ditony. susitcht0- default Content 0) # % boos To Mam page 9% Fame aves . switch te. dative find - element (4. ative - Switch bo. default - Content () gp but © Mam pape Frome 7 Package Frame ) Link_TexT , "WebDriver"). chek O 34 Frome Actives + Quittch to, Frame (a Class Frame’) Antves s Sha element (84. XPATH » “Jn ody [eae eu). “Loney teramat. Outer Trane firmer "Frame: [ioeled Vor. get (itty: demo aueeaton abn” Von) dives - maximize _wsrelow C) Suen. fond — element (4. xeaT » “Ha [normalize ~ Space C) = 'Trrome with vm an IFrame” ] . clic) UU LCULLLUT TEA UV UU VUVYyY F Outer Frame Pind — element (eq. XPATH, "frome {@ ser = " Matuile Fromes. bbl “J > Gesitth_ to» Frame (outer Frame) gbwebelerent: e Outer Frome = Aciver > Aviva Toner Frome nner Frame = doives _ find - element (ey. XPATH * [hiral [body | secon fav [frame °) (immer Frame ) =: datyer . guttch - t- eae Enter Element deter » find - A dnivar» Sv shemant (Oy XPATH 5 "inp ~ te’), Set Keys ( “Welcome ” ich tor Pavert —Arame ©) po gieetty Sash © ent Pome, Coutee From’) UL LULULYLUULULUL Praoweer Windows Switch to. wWmdow (nd rm) Current_ window-handle + Peturm hlindowlp of "Sigle bate” uoindow) * indow_vandte + Retum Nindow Lo of ‘muttioe bowser ” eovedaws daiver. get (ee [ral Shetty seadeny Gm |-AtmanPbc ) Single blindow Whidow Td = diver. Carrent — Winders handle. # Sate winds faim Print, (caine td) f pints Uninc Bd Ergrhme coh e gjecce bozEIBES 4 FEE Bups20eTACE AD Multiple IWlind ows a Approach # 2 ° : ¥ yt y destven - Sond element (6. - [@ia = openwinles!] ) taljdewd 0s = rive .wirdow handles

Table bo: | bey >> Ble bey TL pagueth7 try --4/tr> Lith AI" Cb Livy — - dftrz Table ao etrz -- fey 7 - Lftry | colwe eZ. «set Tae Table data > Admin ——y User Manager * cher find elemert (exer ‘dnia Mobile ]/6”) C1280) ty Users H fn [@id= Ma—admen vied t dviver. fma— element (84. XpaTi, Ie (e | ena Astor — tant") e40 I driver « Fano _ element (84. XpAaTH, "Ye (@ ee mend ~ admin — View System Uses)”, cha ¢) # total ws mumbers Table Len (driver, frid—el ements (By xpath, "WI Pable [@id = ‘reeutt Tle] /] tbody /t*)) Pant (* otal number af OWS Ym Table!” , rows) yous = Court = 0 4 vam (4, roid): anfver- Send — elem ent (cy. XpatH, “abe (ou. Stotus = oan Sao Pose 40 fog Yow i text fe status = = Count = Count + 4° “Emmabted ”: Print ("otal vo ust vous) Paint ( Woris)-Berbled User”: Count) Print ("" to. of disabled user,”, (roe ~ cout) Aviver dose C) x Stordard + Game vnt Gray hebpase thes = Standard Courtomined] : Aigyerent From One Web Fem andl Webpage drtve « aut (1 hetps Ute iccom [ dabepicner ’) J. Stonlord se, divers guitch_to «Frame (0 iv. ed elemet (By. XPATH 5 [ingot (@ %4= lat Picker J ‘), Sat (Crh) # IA 2. Non - Standarrd year 2 "2022" . month = “ March ” Ghee : ide "date picker i t (04. yporn, "linge (ei fuer « find- elemen! ] a click 0) While True : ; ? rine dafver . Svnd_ element Gy XPATH 5 “spn [ences =" tui ~ dal t ' Picker - month’ | J. text PR te data « Sha. element (4. KORN, "spe (Bews : i | "yt date prcker - fear. tex bls Bel 3 \F mz = month and id ze year te , brea © ONSe Se! > / span @efass = ? dua. fvhd lene (oy: xentn "Isp ( 3 I yf tton ait leon brane" Chekl. a Table (@ctass = (ui jdates 2 daiven . find clemenbs (by-xtan," ve eae ° dakepicker — calender ' ody Wa foe 1 in dates: i ates + 33 it ‘text 2 abe a Tcltek() Jive eet ze : bunny ~ Date of birth : aa a) 2. drop dowm date picher deive, get ( https: [roe damp tcke com] date. rmplicitly _wait (20) 16 17 1B 19 20 41 32 95, as AC 47 28.29 303) deiver waving pando) # click to Go awotter PHE- Aviva, . findelemnunt (oy. XPATH + fan fa foot fone Seleck date birth [by ee : Aniver , find — element Coy. Xpa Ta : "Hinpat [ex id= ‘dor’ f a) click) month 2 Select (dates . ind cement (By- eg » foclece (Gort -lobel = ‘Select Month © month. Select by vistde-tert (' Jar) FE Selects the emorth rgeod = Select (sive. $indelememt Gey. xpath, "//Select [Gar ie = “Select year} a) oe selects yoo. dates = Jia 4 mae 40m, "Ptatte [@ class = ‘ut- dete Prcken ~ Calender’ I/Blady [tf tba?) sess ott foy 1 in dates : 4p f, tat == ‘20's t click) break ae aes sec asec ¥ Action Chaims C) \. Mouse hover —> move — to- element (element) 2. Right CVcK - > Content click (element) _ > double - click c elem nt) 3. Double Cltek = hag ond dap (elem) & Drag ond Drop from — Selenium ‘import Webdatver import ActtonCharns for Sena webster TT, | fom & ‘ © Webdsiver + Chaome . Sewice ienpork Gasitte. webditver « Common by import, by Sevice (*Cl| veal coomedhivs. xe") vuwwew rom — Selenium - Sewice objet = datves = webdniver . Chrome (service = Soutce-ofect) © drive. get (" https ll quer + am [astelpcer/’) dump - Catv. Find element lpm (ee oe 0: "Demos act - Actlon Chats ( driver) Atk . move to element « CHECK(. Perfomml) = T ae BesiStaa ss pec =| er leery | def river, get (* beeps |] sutsnl. github fo [ jvens rte Mem [dems hem) bation e detver. 4nd_ element (v4. XPATH, "J[span fedloss 2, Canter! = menu — one bin neutral Ss act - Action Chaves (detvs) act, Cone ct ston). form () a Pform Bit os drive. Pind ~ element (ey. xPaTH. "I span (@ rormalice -Spate () : “copy” |") Clea oT daivey . Sexttth ato. Merk. accepe() 4 clases Alert Pulnideus oer, > Le dsiver. get (“rent J] wow: dbtml qoodia com | Spt sray-dasn— be) drive. ‘empl tly wait (te) = doiver. find element Bip, abone: Yome ‘¢ Haly = drives. Lindelement CBy-T0, "bor ins”) act. drag —ond— daop (vome 5 italy ) - Rrtorm() min 2 99 mar 2 61> driver» get (thee Mess Jqvery Sept et I dum fice -vange ) vevevve ain = datver find element (64. spars, "Cie ep) max dhiver . fend element by. XPATH , "Cl span rap) vue Print (" Before drageng slides”) amin location’) 4f {a 545 oy : asi y Paint Print (max. tocatéon 5) Ca 1251 att Akon Chaim (42ver) ac. drag —and. dvop-by-OFFSeF ‘min , 1008) + perform) act drag = and -d-rp- byaorgset (max s~4010) - rtore 0) Paint ‘¢ " Atter drogen sus) Patnt (amin - location) a { "a": 150, "4" ta515 (max. location ) ee ae 195i ls a Pam wiv e1s4 man © STH By Jue Satpe’s driver get (“het nw. Garda 4 the orld. om [plays - 9 toorld ") daives. maximize cwenlow) 4. Seaoll down page by pixel SW yndow + $¢70 Il by (0, 3000)”, au ) ' daiver. exCeute- Scelpt ( 4 ( “etaqn wrndou + Page Yours } 4 Value- = daiven . €xCeute- oorpt Print (value) de 3000 a. Sesoll_ down by visible text | Flag ~ drivers find—element (84: XPATH, "etd Gammel“ Inowcd] ‘ . ” dhiver . exceute — Script (raaqurents (oJ. fei Otel Value = Aniver. exceute ~ Script (etuon ako -poyeYOrets’) Pafnt (value) # 509-2009 %. St doum page till End riven » ex Ceute - ph (“risidao. soen By Coogdmament bal Sell Hergnt')” > Value = dofves -exceube — script ("rebum wiivlow - page Toner; Paint ( value’) 4r 54%6,.9994 4. $cwll bach to Startvng Point " window - Sevoll By Co, cdowment « body, Scroll Height)” etd dniver. exceute - Sipe G Sion ducklaer wtehnome Chore = 1S Priver get Co btkes + J] beak = Cornpam+ com) “J ae \yiver , ranimiye — Window O) ind — Element (ey. pate. “AE Pppukd = dever « { 3 puttenxt 4°)" Tn put > = diver. Bind — Element (By - xP ATH = 'Grquk Ext 21") Trput 1. Send = Keys Ciivelcome vo reaver!) entoua[@id ='in "Uf kenkancal 24 atcha act = Action chains (awer) aack. Key — dowe bkeys- centeod) sack. Serd— Keys (a) ay act. Key— up C Ket _ CONTRO ay ack. perjorm 0) ack. Kuy — dow (keys conTeoL). Send Keys (sa). Keg oP (Keys ConttRo) . perfor? Cc) col c ar ack - Key. dow (Key. Con'TeoL) + ack. Send = Keys (at ay ack - key up (Kemp. contteol) # ack. perform ( ) ad “Key - down (Kees. Conteoi) . Send Keys Co) Key - up (Keays. contrat). perforrnl ) ; Kags tre) perform L ) ab col P y cack? ay chel TAB — aa send Kup ( re act - Key - down (Key Conteo a ack . Send~ keys ("a") ay deb. Kay — up (Keys - CoN TROL) at ack. Perlore C6 ack. key ~ down (keys. ContTeot) . send — key (ov) - Key —up (key,. ConiTRoL). Pe jor ) ° trnpert Os Locations = 0s. getewd L) | chrome - setup )! i al gelentur webdrive - chrome . Seriice inp! Sie Gertie ~ obj= Servior (tow Users \Userlt Severs ll Chrrave Savers ered envice ~ Ob] = De ee i s+ download fp dated Localten prefients = {downland default dive Ops = Webchiver chrome options () Ops: odd emperinantol _ option (prefs: pefienas ). diver < Webdrive throme (Serva. = Serie = obj» options’ Ops) actus driver ef Fbge = Setiy Ce fro Selenfumr - mubdriver- edge Seni Zenpert Mics feria = Serie (8ex\\usea\ user Ovver \\rnsedy. ctory a location $ Semia — obj dyer. ee y stdoorlosd_io 4 red oction- prefers ~ {dowload default ops = webdriver- edge Options ) ops 083 - enperiroental - optiae (preps: pretrenes) cher = Webliver- Edge (Serica = Sente- okj, options op!) aebuo driver A Automation Code: a diver~ Chao — Setup C) gaver = edge ~ setug L) driver get (ie hbtge« /Flesoerg- ano) Fete Soca" driver « Mand te — piendoio ) ' dhiver. find — Soma (8) ore 'ffuGard “outnt') 3i-O3//4) dick 0 4 _ divecory "2 Location et firefoe — Setup L) ; 4" Selentur - bush driver - fred . bene Trnport Sewice Gerv—obf = Service — (%c: Se I= in | Gulgekodrver exe") + settings { Ops = Webdriver. Fire {ox ogbions( ) ope Set — prajeren™ ("Browser helper pps: Dever Psk.« Sove ToDicks, Wapplicatian [ msvoord") Ops: Sek — preference (" browser. download. manager: Show Wher Stouking” Bilic) Ops. Set ~ preference (Browser. download + Foldertist 2)# O— desley 4 - dowloads folder 2. ~ Desived loc ops: Sek — preferena. ("bmweer- downlod. diy,’ lection). diver = wabbiver- Prefox LSontee = Fore bh, opltos-- ops) veto diver Pag, ASSIS ’ Prepares (2dounland. dealt — deny ' toute, "plugs al i Ope. i race (browser . bel per Apps. newertsk. SaveTo Bek", i Application fede) Hine tag : Ops: Ces Preference Lette dicabled", Fue.) 4h For pdf Oe “Boostrap DES et c “bees: ffeoow Anny ‘ en’) daiver a 4 te _ window 0) Aniver - amaximt , lor ticket = daiver. fib clement (84. XPATH, "CHa pkk tothe, a Lavra (a7) bap copileig 47 2m : Osea. 4 ate Soe ( argomert 10) - sevolntoVeew() 5, Golect biehet) # clrex on option ' Gate . Quad element (@y-XPATH, Aspen few » "bala gl Dilng - cout) ces 0) A Brotstrag Drop Down Countifeslest = Aatyer. fend elements (24. xparn "ul (aa "Select 3 - billing country J Iu °) Gives Uist on Veins (Len (countvtes\ist) | options "ele: 44 fog 3 fm Countata lise: , ey 9. text = 7 “ndéa” : clicw brea Kw dotver, get ("facereot.cm") dviver. Save- ceeenehot (| Ge |Juser If Seleniam [[bome Poa”) H# Total path + Filename import 0S dafver. Save~ Seteenshok (os. getewd C+ “||home- ry a ¥ by frnportg OS tmoduile’- (os.qeteud +” fin) 1 dat ver ye Otreenshot — as- File ——<———— dvlver,qut- veenshot oA base 64 () woaded dative. get (ht: Idemo: nopCommerce ae taad “elon = Hes. ConteoL + Heys Retory LINK Text 5 “Register” ). Sends he yi) lh dakien. find - clement (84. # open Nuwkeh Cutter New Tab Anive « qt (https = I] foccbook. corn”) dnver « susitch AD. mew irdow (‘Sou ) drive + 4ue (* heeys = |} motagron am") ’ * ar open Naw wendow & guithe + mas wirdow wide! a : T foe Tobe 1 | wntegs | ll Acebaok ) cJ0 J | Axved at C" Anives« Switch to ened — Aniver. at CF vgs: fl stoqe™ con") wprrdow (" whdow”) [date Hond web Sowses] dtu 4 qe ¢ hp: [dema.replommerce: ail) —” BWwwVvuvY. Yee of cookies Sa Page © p AE momoer __ coowtes C ) cooKiee = wiver + et Patt c \en ) we wv 3 Ole > oF Ada va Nay Cowie fo page i ve ‘ >, a age i at {ns nye? eee > Coots > sie got ED) » ~ aE mw torre! y ler (canta) print (“an ty ps 4 + Aeletving Cookie drives. dblete - dente (* MyrooW’e ») cookies = dolva. get Corl O Print ie after deletang conics , |e Coootive’) ) lp: HE Dirty delebng, “ll Yeookias - datver » detete all -coortes t) Coovtes = Aviver ge era Print (len Cwontes) ofp: O 2 it qivs Ault”? " gi thowl openiny \prowser + from — Gelenturn import Webdsrve es & det headless — Chrome )s ce yom Selenium « webdsi vey. Chrome» Seni Ce inpor Seek ce & Sewice = Gesutece CC Mose Nehvame driver, ee” & ops = Webdrtvers Chrome opbons () E fs « headless = Te A ee ae clriver = Websrtvey « Chyome (service ae poptins- at) Yebuin deve were ~ | www ~weewwewe datves = headless— Chieme () at C facelooks. tom”) y, ite) #F Foe book. ap ett Ifecbede fom. Acviver « 4 Print (Aaive Print ( doiver. ORL_Current ) datver. closeC) Cam Work with Exel Files ppg laa (-xIsx) ) 2 oo” 93

You might also like