Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 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?

Thanks,

Zea

zea

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

Hi,

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

identifier=id
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.)
id=id
Select the element with the specified @id attribute.
name=name
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

dom=javascriptExpression
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]

xpath=xpathExpression
Locate an element using an XPath expression.

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

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

* link=The link text

css=cssSelectorSyntax
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:

http://seleniumforum.forumotion.net/selenium-ide-discussion-f3/click-a-radio-button-that-has-a-dynamic-id-t135.htm


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

Bye

Adviser
------------------------
------------------------

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

http://seleniumforum.forumotion.net

Back to top Go down

Re: When Xpath not working...

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

Adviser:

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:

/html/body/div[1]/div[2]/div/div[2]/div[1]/div[3]/div[1]/div/div/div[2]/div/div/div/div/div[2]/div/div[2]/div/div/div/div[1]/div[@id=':3n']/div/div/div[@id=':2f']/div[@id=':2c']/div/div/div/div[2]/b

or
div[@id=':2c']/div/div/div/div[2]/b

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!

Zea

zea

Posts : 7
Join date : 2009-09-26

Back to top Go down

Re: When Xpath not working...

Post by Sponsored content Today at 3:07 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