Combining Regex with Selenium in C# -
i have automation suite, testing against wordpress (a test site practice against). attempting verify when user edit's existing page taken correct screen. following code snippet working fine, id mentioned below no longer present (it image).
public static bool isineditmode() { return driver.instance.findelement(by.id("icon-edit-pages")) != null; } assert.areequal(newpostpage.isineditmode(), "you not in edit mode");
the html targeting is...
<h2> edit page <a href="http://localhost/wordpress/wp-admin/post-new.php?post_type=page" class="add-new-h2">add new</a> </h2>
i extract value of h2 tag 'edit page'. getting value of anchor 'add new', need ignore.
using cssselector "h2:first-child" returns both values.
i think need use regular expression, if has suggestions great.
i attempted doing similar in jsfiddle require c# equivalent
var mystring = document.getelementsbytagname('h2')[0].innerhtml; var newstring = mystring.replace(/<([^>]+?)([^>]*?)>(.*?)<\/\1>/ig, ""); console.log(newstring);
you can parent element's text , remove child element's text it:
var parent = driver.findelement(by.tagname("h2")); var child = parent.findelement(by.tagname("a")); var text = parent.text.replace(child.text, "").trim();
Comments
Post a Comment