Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, January 30, 2016

Find the child of the next silbling in selenium java using xpath

Find the child of the next silbling in selenium java using xpath


I am trying to send keys to a text field called Last Name.

Last Name
*

I am able to find the Last Name by using getText feature. What is the cleanest way to get the text field which is the child of the sibling of Last Name ? We use Vaadin to generate the HTML.

Answer by Rafael Teles for Find the child of the next silbling in selenium java using xpath


You can use a full css selector with Selenium to find whathever you want =)

driver.findElement(By.cssSelector("table tbody tr"));  

Answer by Shubham Jain for Find the child of the next silbling in selenium java using xpath


Try below xpath:-

//div[@class='v-captiontext' and //div[contains(@class,'v-captiontext')] and contains(.,'Last Name')]  

Hope it will help you :)

Answer by Karl Gong for Find the child of the next silbling in selenium java using xpath


You can use axes of xpath

//div[text()='Last Name']/following-sibling::div/input  

but I recommend you to use this:

//div[./div[text()='Last Name']]//input  

Answer by Mathias Mller for Find the child of the next silbling in selenium java using xpath


It is not entirely clear what you are expecting as the result. You say:

What is the cleanest way to get the text field which is the child of the sibling of Last Name ?

But it seems that you are not trying to find a sibling of the div element that contains "Last Name", but a sibling of its parent. I also assume that by "text field" you mean an input element. Please try

//div[div = 'Last Name']/following-sibling::div[1]/input  

which will return

  

Answer by Ashish for Find the child of the next silbling in selenium java using xpath


with whatever I can see, I came up with following.

//div[@class='v-captiontext']

I used the //tagname[@attribute='value'] syntax to come up with Xpath.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.