3

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!

1
  • did any of the answers solve your issue? Commented Jan 24, 2020 at 20:29

3 Answers 3

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

found the issue: the url to be searched was not complete without the filtering parameters
2

Try with below css using webdriver wait with visibility of element

xpath = "//em[.= 'C33-8823']/../..//em[2]"
element = WebDriverWait(driver, 20)
    .until(EC.visibility_of_element_located((By.XPATH, xpath)))
element.text

you need below import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

6 Comments

I got this issue:File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
@MartR Please try now. I have updated the solution.
same error... File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
@MartR: I formatted the HTML code in your question and found an issue with the xpath in this answer. I edited this answer to fix the issue.
@GregBurghardt i hv missed one div parent. Thank you
|
1

It happened the page had some display filters that change the url and I was searching on the wrong url.

adding the filter parameters to the address ?statuses%5Bin_progress%5D=1. made it work. Thanks for having a look everyone!

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.