1

I'm new in QA. I'm using VisualStudio 2017 + Selenium WebDriver. I'm Trying driver.FindElementById in Sharepoint 2010 web page.

It is part of the DOM:

<div id="ctl00_MSO_ContentDiv">
<a name="mainContent"></a>
<div style="padding: 20px">
    <h2>
        <span id="ctl00_PlaceHolderMain_LabelCourseTitle">***</span>
    </h2>
    <h3>            
        <span id="ctl00_PlaceHolderMain_LabelClassTitle">***</span>
    </h3>
    <div id="ctl00_PlaceHolderMain_PanelResult">
        <h3>
            <span id="ctl00_PlaceHolderMain_LabelStatus">***</span>
        </h3>
    </div>
</div>

I'm try two times:

1 - it is working!

Thread.Sleep(5000);
driver.FindElementById("ctl00_MSO_ContentDiv");

2 - Error: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"ctl00_PlaceHolderMain_LabelCourseTitle"}

Thread.Sleep(5000);
driver.FindElementById("ctl00_PlaceHolderMain_LabelCourseTitle");

I don't understand, why selenium can't find child elements. All parents of "ctl00_MSO_ContentDiv" can be found. All childs can't be found. Please help.

Update: I can stil find <a name="mainContent"></a>. But every thing bellow I can't find by selenium. Update: Chrome dev tools search elements by XPath normally.

6
  • Can you check css that is applied to your element that cannot be found?
    – Alexey R.
    Jul 3, 2018 at 9:17
  • @AlexeyR. looks like nothing criminal. font-size, font-weight, font-family, color, it is all.
    – Daniel N.
    Jul 3, 2018 at 9:44
  • Can you find the elements in dev tools?
    – Mate Mrše
    Jul 5, 2018 at 9:21
  • @MateMrše yes, by //*[@id="ctl00_PlaceHolderMain_LabelStatus"] or contains(text()...
    – Daniel N.
    Jul 5, 2018 at 12:57
  • Is the element in the page but not visible initially perhaps until you click on that area Aug 4, 2018 at 16:13

2 Answers 2

0

Try this below xpath for locating the child element

//h2/following::span[@id="ctl00_PlaceHolderMain_LabelCourseTitle"];

This xpath will search for the child elements.

8
  • //h2/following::span[@id="ctl00_PlaceHolderMain_LabelCourseTitle"] - I try this in xpath validator with my DOM - doesn't work. And I think it will not wok becouse I try in selenium find just "h3" driver.FindElementByXPath("//h3"); and it is faild (
    – Daniel N.
    Jul 3, 2018 at 13:43
  • if you want to find just h3 then find by using tagname driver.findElement(By.tagName("h3")); This will work Jul 3, 2018 at 13:51
  • The problem is that I can not get any of the items below <div id="ctl00_MSO_ContentDiv"> in my Sharepoint. In any way. driver.FindElementByTagName("h3"); doesn't work.
    – Daniel N.
    Jul 3, 2018 at 13:58
  • Is there any texts present in span tag? Jul 3, 2018 at 14:04
  • Yes, i replace it by ***
    – Daniel N.
    Jul 3, 2018 at 14:11
0

Try with the below xpaths:

//div[@id='ctl00_MSO_ContentDiv']//div[@style]/h2/span[@id='ctl00_PlaceHolderMain_LabelCourseTitle']

//div[@id='ctl00_MSO_ContentDiv']/child::div[@style]/h2/span[@id='ctl00_PlaceHolderMain_LabelCourseTitle']

//div[@id='ctl00_MSO_ContentDiv']/child::div[@style]//div[@id='ctl00_PlaceHolderMain_PanelResult']/h3/span[@id='ctl00_PlaceHolderMain_LabelStatus']
1
  • ( Unable to locate element. With chrome devtools this xpath works fine.
    – Daniel N.
    Jul 5, 2018 at 13:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.