c# - Selenium: Get all text with same id -
the xpath of elements want read (accounting, business, marketing, technology) follows:
/html/body/table/tbody/tr/td[2]/table/tbody/tr/td[2]/font/a /html/body/table/tbody/tr/td[2]/table/tbody/tr/td[4]/font/a /html/body/table/tbody/tr/td[2]/table/tbody/tr[3]/td[2]/font/a /html/body/table/tbody/tr/td[2]/table/tbody/tr[3]/td[4]/font/a
the id of elements is
//font[@class='wlcategorylinkbold']/a
the page testing similar following:
i have following test method:
public void listalllinksinarray() { selobj = new defaultselenium("localhost", 4444, "*iexplore", "http://localhost/crm.aspx"); selobj.start(); selobj.open("http://localhost/crm.aspx"); selobj.selectframe("content"); list<string> topics = new list<string>(); int count = (int)selobj.getxpathcount("//font[@class='wlcategorylinkbold']/a"); (int = 1; <= count; i++) { if (selobj.iselementpresent("//font[@class='wlcategorylinkbold']/a")) { string value = selobj.gettext("//font[@class='wlcategorylinkbold']/a[" + + "]"); topics.add(value); } } string[] arrtopics = topics.toarray(); system.io.file.writealllines(@"c:\writelines.txt", arrtopics); }
the above code writes accounting (once) in text file.
if do:
string value = selobj.gettext("//font[@class='wlcategorylinkbold']/a");
i accounting (4 times) in text file.
what wrong in loop not printing 4 links in text file. in advance!
//someelement[$k]
where $k positive integer, isn't think.
this means:
select elements in xml document named someelement
, $k
-th child of parent.
however, a
elements in xpath expression using, of them seem first , child of parents. means i
different 1 xpath expression selects nothing.
this why first a
selected.
solution:
instead of:
"//font[@class='wlcategorylinkbold']/a[" + + "]"
use:
"(//font[@class='wlcategorylinkbold']/a)[" + + "]"
remember: in xpath []
operator has higher precedence (priority) //
pseudo-operator. way specify different priorities, usual, using brackets.
Comments
Post a Comment