Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to determine XPath for below described case

HTML structure as shown below,

div class = Subject
{ 
  div class = sub
 {

   <span> 'MATHEMATICS' <span>
 }
 
 div class = Score
 {
   
  input class "score|input"
 }
}

div class = Subject
{ 
  div class = sub
 {

   <span> 'CHEMISTRY' <span>
 }
 
 div class = Score
 {
   
  input class "score|input"
 }
}

‘MATHEMATICS’, ‘CHEMISTRY’ are text in span

What I need to do is access the input class based on the text in span.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I don’t know how to access the ‘input’ class based on the text in span. I want to know how to exit that particular nested portion (span) and get into another nested portion in the same class ie. input class = ‘score|input’

Below is the custom Xpath to get till span, beyond this I need help.

div class = Subject // div class = sub // span (over here, I am
unaware of how to read text say, ‘MATHEMATICS’, and move to another
nested portion input class = ‘score|input’)

>Solution :

You can use XPath expression like the following:

//div[@class ='Subject' and .//span[text()='CHEMISTRY']]//input[@class='score|input']

The text value like CHEMISTRY or MATHEMATICS may be passed here as a variable.
You can also use contains method in case of not exact matching text validation, like following:

//div[@class ='Subject' and .//span[contains(text(),'CHEMISTRY')]]//input[@class='score|input']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading