0

I'm a relative newcomer to selenium so this might be something incredibly simple but I can't seem to access an element even though it appears on the page. I don't think it can be that it hasn't loaded yet because I can reference other elements. The line of code I am trying to use and the html is below.

max_questions = driver.find_element_by_xpath(xpath="//span[contains(@class, 'total-questions')]")

<div data-v-404a90e7="" data-v-084771db="" class="header animated fadeInDown anim-300-duration">
    <div data-v-404a90e7="" class="left-section half-width">
        <div data-v-404a90e7="" flow="right" class="menu-icon animated fadeIn anim-300-duration">
            <div data-v-404a90e7="" class="menu-icon-image"></div>
        </div>
        <div data-v-404a90e7="" class="question-number-wrapper text-unselectable animated fadeIn anim-300-duration">
            <span data-v-404a90e7="" class="current-question">1</span>
            <span data-v-404a90e7="" class="total-questions">/10</span>
        </div>
    </div>
    <div data-v-404a90e7="" class="right-section half-width">
        <div data-v-404a90e7="" class="room-code animated fadeIn anim-300-duration">712851</div>
        <div data-v-404a90e7="" flow="left" class="exit-game-btn-wrapper animated fadeIn anim-300-duration">
            <div data-v-404a90e7="" class="exit-game-icon"></div>
        </div>
    </div>
</div>
1
  • check if it is inside iframe, if so switch to frame Commented Jan 10, 2019 at 16:41

1 Answer 1

1

You can use WebDriverWait with expected_conditions:

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

driver = webdriver.Chrome('d:\\chromedriver\\chromedriver.exe')
driver.get(url)
wait = WebDriverWait(driver, 10)
max_questions = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(@class, 'total-questions')]")))
print(max_questions.text)
Sign up to request clarification or add additional context in comments.

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.