In: Computer Science
1) Write an XPath expression to find all elements (anywhere in the input document) having a born element anywhere inside them.
2) What does the XPath expression /html/body//div[1] return?
3) Write an XPath expression to find all elements (anywhere in the input document) that do not have an id attribute.
1) Xpath expression to find all elements having a born element anywhere inside them
Exaple:
Xpath=//input[@type='txt'] Xpath= //label[@id='message'] Xpath= //input[@value='reset'] Xpath=//*[@class='classname'] Xpath=//a[@href='http://abc.com/'] Xpath= //img[@src='//java.png']
2.)What does the XPath expression /html/body//div[1] return?
/html/body//div[1] this expression called Absolute path. It means the direct way to find the element,it begins with the single forward slash(/) ,means you can select the element from the root node.
It have advantage:
if there are any changes made in the path of the element then that XPath gets failed.
3)When we don't have id attribute then we can take the contains with text and name.
Example:
Xpath=//*[contains(@name,'bt')];
Xpath=//*[contains(@type,'text')]
// means its a relative path, It starts from the middle of HTML DOM structure
It can search elements anywhere on webpage, It means no need to write a long xpath