I'm trying to figure out a way to use CSS selectors to isolate a specific child of a div.
I want the selector to apply only to the input nested within #section1 and not within #section2.
<div class="section" id="section1">
    <div class="section" id="section2">
        <input type="text">
    </div>
    <input type="text">
</div>
This is a simplified example, but here are some notable things:
- the divs are uniquely identifiable but have a common class
- the two inputs are exactly identical in every way (except for their location), but eachdiv.sectiononly has uniqueinputs that aren't further nested within otherdiv.sections
- the location of a div.section'sinputcould change, meaning that it could come before or after the nested div with an identical input (ruling out:nth-child(n)or:nth-of-type(n)) but it will still be in the level
- there are a mess of other divs in and surrounding all of this code for formatting reasons
- I didn't write the code and I can't change the code
If it's relevant, I'm using WebdriverIO to interact with the page, but it doesn't include much else except CSS selectors to find elements on the DOM (except for linking text, which isn't very useful here).
Let me know if I can clarify the scenario more. I couldn't find any questions similar enough to this (most were for styling and could be resolved by overriding the styling for the nested one) but please let me know if I missed something.
Edit: A more accurate example (with the complicated mess and extra inputs) looks more like this...
<div class="section" id="section1">
    <div>
        <div class="section" id="section2">
            <input type="text" class="input1">
            <input type="text">
        </div>
    </div>
    <div>
        <div>
            <div class="section" id="section3">
                <input type="text">
                ...
            </div>
        </div>
    </div>
    <div>
        <input type="text" class="input1">
        ...
    </div>
</div>
<div class="section" id="section4">
    ...
</div>
In this example, both input.input1 are children of #seciont1, but I want them to be associated with their nearest parent div.section. So the first occurring one would be associated with #section2 and the second with #section1.
So there could necessarily be extraneous code nested or surrounding any parts, but it is distinguishable for the important stuff. I just can't use the child selector > because it won't be a direct child.
There can also be more div.sections nested in any which way with more input, but there will only be unique inputs within each div.section that isn't further nested within a different div.section.
I'm also not using it for styling, so I can't overwrite with a second selector. I need the one selector to uniquely identify the correct input with it's closest parent div.section.
 
     
     
     
    