How many types of xpath are there?

 In Selenium, there are mainly two types of XPath used for locating elements: 1. Absolute XPath: This XPath starts from the root node and follows the complete path to the element. It is highly specific and is dependent on the structure of the HTML document. Example: /html/body/div[1]/div[2]/div[1]/span 2. Relative XPath: This XPath starts from any element in the HTML document (not necessarily from the root). It is more flexible and commonly used because it is less likely to break if the structure of the page changes slightly. Example: //div[@class='example'] Additionally, XPath can be classified by the type of syntax used for selecting elements: Attribute-based XPath: Selects elements based on their attributes (e.g., id, class, name, etc.). Example: //input[@name='username'] Text-based XPath: Selects elements based on their text content. Example: //button[text()='Submit'] Contains() function: Allows partial matching of attributes or text. Example: //a[contains(@...

String[] things - POST BY LEW BALOCH

POST BY LEW BALOCH


`String[] things` or `String things[]`?
Both are legal but one is wrong.
Yet we see people putting the brackets actually *after the variable* instead of with the base type where they belong.


Gasp!

The JLS says
"Brackets are allowed in declarators as a nod to the tradition of C and C++"
https://lnkd.in/dQ585t5c
but that doesn't read idiomatically in Java.

Or worse, brackets can appear after a method signature's parameter list:
Identifier ( [ReceiverParameter ,] [FormalParameterList] ) [Dims]

but:
"The declaration of a method that returns an array is allowed to place some or all of the bracket pairs that denote the array type after the formal parameter list. This syntax is supported for compatibility with early versions of the Java programming language. It is very strongly recommended that this syntax is not used in new code."
https://lnkd.in/dRAjpMMj

Think: is the type an array of String named `args` "String array" or "args array". Obviously since `args` is not a type, it's "String array".
So when you read
String[] args
String args[]
which one reads "a String array named 'args'"
and which one "a String named 'args', no wait, it's an array"?

Just because you can doesn't mean you should.

Comments

Popular posts from this blog

What is the default package in Java if no package is specified?

Sample Questions for ISTQB (SET-2)