Pergunta

I am new to Watir framework and we have a code like

$browser.link(:xpath, "//a[@href='/servlets/ProcessAction?identifier=createMemberAccountTypes&click1=Accounts_Open']").click 

. But this works well on IE but not on Firefox always. So we use something like

$browser.span(:text => "Logout").parent.click

However we dont want to write one for IE and one for Firefox. What should we use?

Thank you for your time.

Foi útil?

Solução

I would use:

$browser.link(:text => "Logout").click

The :text specifier includes all text in the element and its elements (ie includes that in the span). Therefore you can get the link directly, rather than getting the parent of the span.

The usual suggestion is to avoid xpath where possible. It is often harder to read and can be brittle. For example, your xpath is hard-coded to a specific order of the querystring parameters. If the url generated becomes '/servlets/ProcessAction?click1=Accounts_Open&identifier=createMemberAccountTypes' (ie order of parameters changes), your test will fail. In contrast, the text "Logout" seems less likely to change.

In general, I would say use what works.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top