Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium and JSF 2.0

When I a generate SelectOneMenu with JSF2.0 the the id I specified in the xhtml is attached to a generated ID from JSF.

e.g. out of my_fancy_id it generates j_idt9:my_fancy_id

Now I want to test my page with Selenium 2 Web Driver. I try to re-find my select menu:

driver.findElement(By.id("my_fancy_id"));

Of course it does't find anything because the id is changed. What is the best way to find the select menu on the page?

like image 279
bertolami Avatar asked Dec 28 '22 14:12

bertolami


2 Answers

Usually the id of the form is prepended to all element ids inside the form. If you don't set a form id, JSF does it for you (the 'j_idt9'). Solution: Assign an id to your form and try to use the full id in your findElementmethod, e.g.:

<h:form id="myForm">
 ...
</h:form>

Call it this way:

driver.findElement(By.id("myForm:my_fancy_id"));
like image 111
Matt Handy Avatar answered Jan 18 '23 04:01

Matt Handy


or you can add <h:form prependId="false"> so that the id of the form does not get prepended

like image 24
gautirao Avatar answered Jan 18 '23 05:01

gautirao