XPath-Funktionen fĂŒr dynamisches XPath in Selen

Wir laden zukĂŒnftige Studenten des Kurses "Java QA Automation Engineer" und alle Interessierten ein, sich eine Demo-Lektion im Format eines offenen Webinars anzusehen .



Wir teilen auch die Übersetzung eines nĂŒtzlichen Artikels.










Dieser Artikel beschreibt Beispiele fĂŒr die Verwendung von XPath-Funktionen zum Identifizieren von Elementen.





Die Automatisierung der Interaktion mit einem beliebigen Standort beginnt mit der korrekten Identifizierung des Objekts, an dem eine Operation ausgefĂŒhrt wird. Wie wir wissen, können Sie ein Element am einfachsten anhand von Attributen wie ID, Name, Link, Klasse oder anderen eindeutigen Attributen identifizieren, die in dem Tag verfĂŒgbar sind, in dem sich das Element befindet.





Es ist jedoch nur möglich, ein Objekt korrekt zu identifizieren, wenn solche Attribute vorhanden und / oder eindeutig sind.





=>  Selenium .





[]





XPath

, .





, , ID, Name, Class Link, ?





:





 Twitter





, «Log in to Twitter» . , ID



, Class



, Link



Name



, .





Firepath Firefox XPath:





//[@id=’page-container’]/div/div[1]/h1





XPath, id . XPath, , , . , XPath , ID, Class, Link Name.









XPath

«Log in to Twitter», XPath



.





  1. contains() [ ]





  2. starts-with() [ ]





  3. text()





XPath



, contains()



, starts-with()



text()



, «Log in to Twitter» , .





1. Contains()

.  - «Log in to Twitter», XPath contains()



.





:





  • //h1[contains(text(),’ Log in to’)]







  • //h1[contains(text(),’ in to Twitter’)]







. -.





, contains()



. , . contains()



, , .





, «Log in to Twitter» contains()



.





2. starts-with()

.  - «Log in to Twitter», XPath starts-with().





:





  • //h1[starts-with(text(),’Log in’)]







  • //h1[starts-with(text(),’Log in to’)]







, XPath- starts-with()



(«Log») . , .





, «Log in to Twitter» starts-with()



.





XPath starts-with()



: //h1[starts-with(text(),’in to Twitter’)]







.  , - .





3. text()

.  - «Log in to Twitter», XPath



text()



.





, <h1>



</h1>



. text()



, contains()



starts-with()



, .





Xpath text()



:





XPath

XPath



(contains



starts-with



) , . «@



».









 Google





1. Contains()

.  «I’m Feeling Lucky» (« ») XPath- contains()



, .





 â€” Value







  • //input[contains(@value,’Feeling’)]







  • //input[contains(@value,’Lucky’)]







, Value



«Feeling» «Lucky» contains()



. , , Value



, .





— Name







//input[contains(@name=’btnI’)]







XPath :





contains()



starts-with()



. , .





type



«I'm Feeling Lucky», XPath .





, . type



.





2. starts-with()

starts-with()



, , . , . .





 Facebook.





First Name () Surname () .





First Name .





Surname .





, Facebook, id



.





First Name id="u02"





Surname id="u04"





, starts-with()



, id



. , . id



, «u0».





Starts-with() [ id]





//input[starts-with(@id,"u0")]







.  . starts-with



.





11 , XPath , id



«u0». id



(«2» , «4» . .) .





starts-with



, , , .





starts-with



.









/ <strong>Generic Method</strong> /





 





public void xpathLoc(String identifier){





    //The below step identifies the element “First Name” uniquely when the argument is “2”





WebElement E1=d1.findElement(By.xpath("//input[starts-with(@id,”u0”+identifier )]"));





E1.sendKeys(“Test1”);  / This step enters the value of First Name as “Test 1” /





}





/ <strong>Main Method</strong>*/





 





public static void main(String[] args) {





        xpathLoc(“2”); --- This step calls the xpathLoc() method to identify the first name.





        }





. Eclipse . , , XPath.





. , , ( ), .





, XPath contains()



, starts-with()



text()



HTML DOM.





XPath:

  1. contains()



    XPath, .





  2. starts-with()



    XPath, .





  3. contains()



    starts-with()



    .





  4. text()



    XPath, .





  5. text()



    .





  6. starts-with()



    , XPath .





, XPath XPath -.






, . , 100 ?





.



"Java QA Automation Engineer"
.












All Articles