Display results as :

Rechercher Advanced Search


When Xpath not working...

View previous topic View next topic Go down

When Xpath not working...

Post by zea on Fri Nov 13, 2009 6:26 am

In many cases Xpath not working at all,

for instance:
Gmail->Compose Mail -> Send button

XPath: //div[@id=':6o']/div/div/div[@id=':5j']/div[@id=':5g']/div/div/div/div[2]/b

but the next time all the above ids will be changed

So how do you defind these kind of elements if their ids are dynamically changed and do not have ids/names?




Posts : 7
Join date : 2009-09-26

Back to top Go down

Re: When Xpath not working...

Post by Adviser on Sat Nov 14, 2009 6:08 pm


you can identify the element in selenium in many different ways like:

Select the element with the specified @id attribute. If no match is found, select the first element whose @name attribute is id. (This is normally the default; see below.)
Select the element with the specified @id attribute.
Select the first element with the specified @name attribute.

* username
* name=username

The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.

* name=flavour value=chocolate

Find an element using JavaScript traversal of the HTML Document Object Model. DOM locators must begin with "document.".

* dom=document.forms['myForm'].myDropdown
* dom=document.images[56]

Locate an element using an XPath expression.

* xpath=//img[@alt='The image alt text']
* xpath=//table[@id='table1']//tr[4]/td[2]

Select the link (anchor) element which contains text matching the specified pattern.

* link=The link text

Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.

* css=a[href="#id3"]
* css=span#firstChild + span

Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).

Without an explicit locator prefix, Selenium uses the following default strategies:

* dom, for locators starting with "document."
* xpath, for locators starting with "//"
* identifier, otherwise

Try to use other methods instead of xpath. check out the following thread also:

This will give you some hint regarding your problem. Best Of luck.



Posts : 379
Join date : 2009-07-30
Location : India

Back to top Go down

Re: When Xpath not working...

Post by zea on Mon Nov 16, 2009 1:51 pm


Thank you so much for all the above hints. I want to try the mapped approach:

storeAttribute| path of area where radiobutton placed @ id| variableName
click| ${variableName}

The last time the xpath is:



So I tried:
storeAttribute| //div @ id| x
but failed to save the id to x

In this case what should I put in front of @ id?

Please advise and thanks a lot!



Posts : 7
Join date : 2009-09-26

Back to top Go down

Re: When Xpath not working...

Post by Sponsored content Today at 3:46 pm

Sponsored content

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

Permissions in this forum:
You cannot reply to topics in this forum