field

I need to check / make sure that the text "( carrier specific )" exists and is in the right place.

I do

 try: self.assertEqual("(carrier specific)", sel.get_table("//form/fieldset[4]/table.2.1")) 

but he does not want to "pick up" this text (refers to the empty field of National prefix , but not to the text immediately after it). I need to somehow determine the location of this text on the page, i.e. access this element via xpath / css.

 <fieldset class="group"> <fieldset class="group"> <fieldset class="group"> <fieldset class="group"> <legend>Dialing Location</legend> <table> <tbody> <tr title="The country code."> <tr title="The area code."> <tr title="The national trunk prefix."> <td>National Prefix</td> <td> <input maxlength="256" size="10" value="" name="dl-ntp"> (carrier specific) </td> </tr> 

code

  • Interestingly, do you use python ? And so, you probably will help next-sibling or something like that. And it is better to add that table to the question as text (you can leave the picture) - gil9red
  • In question, please. править button - gil9red

1 answer 1

xpath to get the text from the node you described: //input[@name='dl-ntp']/../text()[boolean(string-length(normalize-space(.)))]

xpath to check for the expected text to match in the described node: //input[@name='dl-ntp']/ancestor::*[1][contains(.,'carrier specific')] dl-ntp'_RL/ //input[@name='dl-ntp']/ancestor::*[1][contains(.,'carrier specific')] :: //input[@name='dl-ntp']/ancestor::*[1][contains(.,'carrier specific')]

If you are using python, it can be useful: driver.execute_script("return document.evaluate('//input[@name='dl-ntp']/../text()[boolean(string-length(normalize-space(.)))]', document, null, XPathResult.ANY_TYPE, null).iterateNext().data")