Home > Blockchain >  Unable to determine XPath for below described case
Unable to determine XPath for below described case

Time:01-27

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.

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')

CodePudding user response:

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']
  •  Tags:  
  • Related