Matrices

How can I select this span element?

I am just starting with Selenium and now you need to select this element:

<span class=" close">Matrices</span>

This line of code returns null elements, so I assume this is not correct :-)

ReadOnlyCollection<IWebElement> matrixLink = driver.FindElements(By.PartialLinkText("Matrices"));

But I couldn’t find a suitable one other than Xpath, but it looks like this ( //*[@id=\"Navigation\"]/div[2]/div[2]/ul/li[7]/span) and it seems a little fragile for me?

EDIT : span has a class of "close". This is part of the menu, where there are 19 spans with the "close" class, so it is not a unique selector, unfortunately ....

+5
source share
3 answers

This will work:

//*[@id=\"Navigation\"]/descendant::span[text()='Matrices']

, XPath, ... * all . , , , , div, :

//div[@id=\"Navigation\"]/descendant::span[text()='Matrices']

XPath , Navigation - , span, Matrices. descendant XPath . , , Navigation, - , TestDiv, Navigation, descendant , .

, By.PartialLinkText , . , , span span .

By.PartialLinkText By.LinkText "" , .

+8

:

, N- "" (//span[7] - )

+2

You can use // span [text () = 'Matrices'] It will select your element.

+2
source

All Articles