1

Following is how the element looks like on the page:

enter image description here

I want all the li which comes right after General Engineering Courses. General [COURSE_NAME] Courses is common text on other pages as well.

So basically I want all the li which come right after GENERAL [COURSE_NAME] Courses.

I wrote the following XPath, but unfortunately, it's causing DOMException while executing the XPath on Chrome.

//*[starts-with(text(), 'GENERAL') and ends-with(text(), 'COURSES')]

enter image description here

Page: http://catalog.fullerton.edu/content.php?catoid=16&navoid=1922

miserable
  • 697
  • 1
  • 12
  • 31
  • 1
    Duplicate of [XPath for element whose attribute value ends with a specific string?](https://stackoverflow.com/questions/40934644/xpath-for-element-whose-attribute-value-ends-with-a-specific-string) – kjhughes Mar 14 '18 at 13:20
  • `ends-with()` requires XPath 2.0, and browsers only support XPath 1.0. See duplicate link for a work-around. – kjhughes Mar 14 '18 at 13:21
  • Try `//*[starts-with(text(), 'GENERAL') and substring(text(), string-length(text()) - string-length('COURSES') +1) = 'COURSES']` – Andersson Mar 14 '18 at 13:22

1 Answers1

0

You need use XPath Axes, the following-sibling

//p[starts-with(strong,'GENERAL ') and substring(strong, string-length(strong)-7)=' COURSES']/following-sibling::ul/li
Adam Silenko
  • 3,025
  • 1
  • 14
  • 30