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, ?
:
, «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
.
contains() [ ]
starts-with() [ ]
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
) , . «@
».
:
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()
, , . , . .
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:
contains()
XPath, .
starts-with()
XPath, .
contains()
starts-with()
.
text()
XPath, .
text()
.
starts-with()
, XPath .
, XPath XPath -.
, . , 100 ?
.
"Java QA Automation Engineer" .