0

I am trying to select an element using CSS selector (and have tried XPath also).

<div data-sheetstartpoint="1">
    <div class="booking">
        <div class="startsheet two">
            <div class="title">
                <div class="time">Time</div>
                <div class="cols">
                    <div class="hidden-xs two">Team 1</div>
                    <div class="hidden-xs two">Team 2</div>
                    <div class="visible-xs two">Teams</div>
                </div>
            </div>
            <div class="slot" data-startpointno="1">
                <div class="time" id="timelabel"> 07:30 </div>
                <div class="cols">
                    <div class="timeslot  " data-roundteamid="" data-slotno="1" data-time="17/04/2021 06:30:00" data-startpointno="1" data-offset="0" data-bookingname="">
                        <span class="available-to-book">Available </span>
                    </div>
                    <div class="timeslot  " data-roundteamid="" data-slotno="2" data-time="17/04/2021 06:30:00" data-startpointno="1" data-offset="0" data-bookingname="">
                        <span class="available-to-book">Available </span>
                    </div>
                </div>
            </div>

I have made a CSS selector (and have also looked using Chropath) I am getting an element not found error. The selectors I am using

FindElementByCss(".timeslot[data-slotno*='1'][data-time*='17/04/2021 06:30:00']")

FindElementByXPath("//*[@id='hdidbookingcontent']/div[2]/div[1]/div/div[3]/div[2]/div[1]")

I see further up the page there is a class "container" - is this something that would impact selection?

9
  • Have you looked to see if they are in an IFRAME?
    – JeffC
    Apr 17, 2021 at 4:22
  • 1
    Your CSS selector works fine but you don't need the * before = on either of them. *= means contains but neither need it because they equal those values. We can't check the XPath because you didn't include that relevant HTML for the ID and down. I would not suggest that XPath given the number of levels and most with just indices. That's going to break very easily with minor page changes.
    – JeffC
    Apr 17, 2021 at 4:27
  • Hi I am not sure if they are in an I frame not something I know anything about . I will try to find out . Ok re the * I think perhaps earlier I had the data time only as 17. Glad to hear I have the actual css selectors pretty much right (even if they are not yet fi d g what I want!) Thanky you got help
    – Richard Br
    Apr 17, 2021 at 17:10
  • Hi As far as I can see there is no iframe involved. I have modified the CSS selectors as suggested but still get "No such ElementError".
    – Richard Br
    Apr 26, 2021 at 21:11
  • 1
    Hi Unfortunately this is a members page which I think I am unable to share. When opening using selenium there is no new tab showing in browser. When opening manually there is a new tab. I have used .switch to next window and my CSS selectors are now working. Thank you for explaining CSS selectors (I have hopefully grasped) and also demonstrating use in console. On to the next stage and thanks once again for your time and assistance
    – Richard Br
    Apr 28, 2021 at 11:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.