Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find element inside div with xpath or css selector

I am trying to get "January 27" as output with this code:

task_offer_deadline = driver.find_element_by_xpath('//*[@id="table"]/div[2]/div/a/div[1]/span[2]/div/em').text

the xpath provided by Google Chrome Console. This was the html source:

<div class="content table-contents">
    <a class="one is-incomplete" href="/authors/tasks/5e2ad33c2b3dc80013d3dba6">
        <div class="left part">
            <span class="ref">
                <em>C33-8823</em>
                <strong class="date"></strong>
            </span>
            <span class="deadline-or-countdown">
                <div class="deadline-at">
                    <em class="green">January 27</em>
                </div>
            </span>

but it cannot be found. I even tried with other types of search, id, class name, all to no avail. Any clues why? thanks a lot!

like image 225
Mart R Avatar asked Mar 06 '26 11:03

Mart R


1 Answers

Try this xpath:

xpath = //span[@class='deadline-or-countdown']/div[@class='deadline-at']/em

If this also doesn’t help, then make sure your element is not inside the <iframe>.

If the element is in the iframe, then you need to switch to it before looking for the element:

iframe = driver.find_element_by_xpath("//iframe[@name='Dialogue Window']")
driver.switch_to.frame(iframe)
like image 109
Evgeniy Chiruk Avatar answered Mar 08 '26 02:03

Evgeniy Chiruk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!