Selenium is not properly determining if a page has a html tag</a></h1> </div> <div class="grid fw-wrap pb8 mb16 bb bc-black-075"> <div class="grid--cell ws-nowrap mr16 mb8" title="2016-01-12 19:07:53Z"> <span class="fc-light mr2">Asked</span> <time itemprop="dateCreated" datetime="2018-12-22T01:14:09.347" class="fromnow">Dec 22 '18 at 01:14</time> </div> <div class="grid--cell ws-nowrap mr16 mb8"> <span class="fc-light mr2">Active</span> <time class="fromnow" title="2018-12-23T17:55:57.990" datetime="2018-12-23T17:55:57.990">Dec 23 '18 at 17:55</a> </div> <div class="grid--cell ws-nowrap mb8" title="Viewed 1,395 times"> <span class="fc-light mr2">Viewed</span> 1,395 times </div> </div> <div id="mainbar" role="main" aria-label="questions and answers"> <div id="question" class="question" data-questionid="53892345" data-ownerid="9962875" data-score="0"> <div class="post-layout"> <div class="votecell post-layout--left"> <div class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="53892345"> <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"></path></svg></button> <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="0">0</div> <button class="js-bookmark-btn s-btn s-btn__unset c-pointer py4"> <svg aria-hidden="true" class="svg-icon iconBookmark" width="18" height="18" viewBox="0 0 18 18"><path d="M6 1a2 2 0 00-2 2v14l5-4 5 4V3a2 2 0 00-2-2H6zm3.9 3.83h2.9l-2.35 1.7.9 2.77L9 7.59l-2.35 1.7.9-2.76-2.35-1.7h2.9L9 2.06l.9 2.77z"></path></svg> <div class="js-bookmark-count mt4" data-value=""></div> </button> </div> </div> <div class="postcell post-layout--right"> <div class="s-prose js-post-body" itemprop="text"><p>I'm trying to get Selenium to wait until the title tag of a web page is present when loading with Python.</p> <p>I've tried testing this code with other types of HTML tags and only the <code><body></code> tag didn't result in an error.</p> <pre><code>wait = WebDriverWait(driver, 10) driver.get(link) wait.until(EC.visibility_of_element_located((By.TAG_NAME, 'div'))) </code></pre> <p>I expected the code to evaluate to completion but I got the following error:</p> <pre><code>Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: </code></pre></div> <div class="mt24 mb12"> <div class="post-taglist grid gs4 gsy fd-column"> <div class="grid ps-relative"> <a href="../../questions/tagged/python" class="post-tag js-gps-track" title="show questions tagged 'python'" rel="tag">python</a> <a href="../../questions/tagged/selenium" class="post-tag js-gps-track" title="show questions tagged 'selenium'" rel="tag">selenium</a> <a href="../../questions/tagged/selenium-webdriver" class="post-tag js-gps-track" title="show questions tagged 'selenium-webdriver'" rel="tag">selenium-webdriver</a> <a href="../../questions/tagged/webdriverwait" class="post-tag js-gps-track" title="show questions tagged 'webdriverwait'" rel="tag">webdriverwait</a> <a href="../../questions/tagged/page-title" class="post-tag js-gps-track" title="show questions tagged 'page-title'" rel="tag">page-title</a> </div> </div> </div> <div class="mb0"> <div class="mt16 grid gs8 gsy fw-wrap jc-end ai-start pt4 mb16"> <div class="grid--cell mr16 fl1 w96"></div> <div class="post-signature grid--cell"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="edited Dec 23 '18 at 17:55">edited Dec 23 '18 at 17:55</time> <a href="../../users/1016716/mr-lister" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/1016716.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="Mr Lister" /> </a> <div class="s-user-card--info"> <a href="../../users/1016716/mr-lister" class="s-user-card--link">Mr Lister</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">45,515</li> <li class="s-award-bling s-award-bling__gold" title="15 gold badges">15</li> <li class="s-award-bling s-award-bling__silver" title="108 silver badges">108</li> <li class="s-award-bling s-award-bling__bronze" title="150 bronze badges">150</li> </ul> </div> </div> </div> <div class="post-signature owner grid--cell"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="asked Dec 22 '18 at 01:14">asked Dec 22 '18 at 01:14</time> <a href="../../users/9962875/george-thompson" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/9962875.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="George Thompson" /> </a> <div class="s-user-card--info"> <a href="../../users/9962875/george-thompson" class="s-user-card--link">George Thompson</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">81</li> <li class="s-award-bling s-award-bling__silver" title="1 silver badges">1</li> <li class="s-award-bling s-award-bling__bronze" title="8 bronze badges">8</li> </ul> </div> </div> </div> </div> </div> </div> <div class="post-layout--right js-post-comments-component"> <div id="comments-53892345" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="53892345" data-min-length="15"> <ul class="comments-list js-comments-list" data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true"> <li id="comment-94631403" class="comment js-comment " data-comment-id="94631403" data-comment-owner-id="771848" data-comment-score="0"> <div class="js-comment-actions comment-actions"> <div class="comment-score js-comment-edit-hide"> </div> </div> <div class="comment-text js-comment-text-and-form"> <a name="comment94631403_53892345"></a> <div class="comment-body js-comment-edit-hide"> <span class="comment-copy">Does that page actually have any `div` elements?</span> – <a href="../../users/771848/alecxe" title="462,703 reputation" class="comment-user ">alecxe</a> <span class="comment-date" dir="ltr"><a class="comment-link" href="../../questions/53892345/selenium-is-not-properly-determining-if-a-page-has-a-title-html-tag#comment94631403_53892345"><span title="2018-12-22T01:23:03.967 License: CC BY-SA 4.0" class="relativetime-clean">Dec 22 '18 at 01:23</span></a></span> </div> </div> </li> </ul> </div> </div> </div> </div> <div id="answers"> <a name="tab-top"></a> <div id="answers-header"> <div class="answers-subheader grid ai-center mb8"> <div class="grid--cell fl1"> <h2 class="mb0" data-answercount="9">2 Answers<span style="display:none;" itemprop="answerCount">2</span></h2> </div> </div> </div> <a name="53892421"></a> <div id="answer-53892421" class="answer accepted-answer" data-answerid="53892421" data-ownerid="6124411" data-score="3" itemprop="acceptedAnswer" itemscope="" itemtype="https://schema.org/Answer"> <div class="post-layout"> <div class="votecell post-layout--left"> <div class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="53892421"> <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"></path></svg></button> <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="3">3</div> <div class="js-accepted-answer-indicator grid--cell fc-green-500 py6 mtn8"><div class="ta-center"><svg aria-hidden="true" class="svg-icon iconCheckmarkLg" width="36" height="36" viewBox="0 0 36 36"><path d="m6 14 8 8L30 6v8L14 30l-8-8v-8z"></path></svg></div></div> </div> </div> <div class="postcell post-layout--right"> <div class="s-prose js-post-body" itemprop="text"><p>The <code>title</code> tag is never <em>visible</em>. You can wait for its <em>presence</em>, though:</p> <pre><code>wait.until(EC.presence_of_element_located((By.TAG_NAME, 'title'))) </code></pre> <p>The title also has its own expected conditions, <code>title_is()</code> and <code>title_contains()</code>. For example:</p> <pre><code>wait.until(EC.title_is("Google")) </code></pre> <p>You can review the complete list of supported expected conditions in the <a class="external-link" href="https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.support.expected_conditions" rel="nofollow noreferrer">documentation</a>.</p></div> <div class="mb0"> <div class="mt16 grid gs8 gsy fw-wrap jc-end ai-start pt4 mb16"> <div class="grid--cell mr16 fl1 w96"></div> <div class="post-signature grid--cell"> <div class="user-info "> <div class="user-action-time">edited <span title="2018-12-22T01:45:17.233" class="relativetime">Dec 22 '18 at 01:45</span></div> <div class="user-gravatar32"></div> <div class="user-details" itemprop="author" itemscope="" itemtype="http://schema.org/Person"> <span class="d-none" itemprop="name">cody</span> <div class="-flair"></div> </div> </div> </div> <div class="post-signature grid--cell"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="answered Dec 22 '18 at 01:39">answered Dec 22 '18 at 01:39</time> <a href="../../users/6124411/cody" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/6124411.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="cody" /> </a> <div class="s-user-card--info"> <a href="../../users/6124411/cody" class="s-user-card--link">cody</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">11,045</li> <li class="s-award-bling s-award-bling__gold" title="3 gold badges">3</li> <li class="s-award-bling s-award-bling__silver" title="21 silver badges">21</li> <li class="s-award-bling s-award-bling__bronze" title="36 bronze badges">36</li> </ul> </div> </div> </div> </div> </div> </div> <div class="post-layout--right js-post-comments-component"> <div id="comments-53892421" class="comments js-comments-container bt bc-black-075 mt12 " data-post-id="53892421" data-min-length="15"> <ul class="comments-list js-comments-list" data-remaining-comments-count="0" data-canpost="false" data-cansee="true" data-comments-unavailable="false" data-addlink-disabled="true"> <li id="comment-94643056" class="comment js-comment " data-comment-id="94643056" data-comment-owner-id="9962875" data-comment-score="0"> <div class="js-comment-actions comment-actions"> <div class="comment-score js-comment-edit-hide"> </div> </div> <div class="comment-text js-comment-text-and-form"> <a name="comment94643056_53892421"></a> <div class="comment-body js-comment-edit-hide"> <span class="comment-copy">Wow thanks a lot for the help! This definitely was a head-scratcher; I should have payed much more attention to the actual meaning of the method's name.</span> – <a href="../../users/9962875/george-thompson" title="81 reputation" class="comment-user owner">George Thompson</a> <span class="comment-date" dir="ltr"><a class="comment-link" href="../../questions/53892345/selenium-is-not-properly-determining-if-a-page-has-a-title-html-tag#comment94643056_53892421"><span title="2018-12-22T19:42:36.307 License: CC BY-SA 4.0" class="relativetime-clean">Dec 22 '18 at 19:42</span></a></span> </div> </div> </li> </ul> </div> </div> </div> </div> <a name="53895407"></a> <div id="answer-53895407" class="answer " data-answerid="53895407" data-ownerid="7429447" data-score="0" itemprop="suggestedAnswer" itemscope="" itemtype="https://schema.org/Answer"> <div class="post-layout"> <div class="votecell post-layout--left"> <div class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200" data-post-id="53895407"> <button class="js-vote-up-btn grid--cell s-btn s-btn__unset c-pointer"><svg aria-hidden="true" class="m0 svg-icon iconArrowUpLg" width="36" height="36" viewBox="0 0 36 36"><path d="M2 26h32L18 10 2 26z"></path></svg></button> <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="0">0</div> </div> </div> <div class="postcell post-layout--right"> <div class="s-prose js-post-body" itemprop="text"><p>If you want to access the <em>Page Title</em> locating the <code><title></code> tag is not the ideal way.</p> <p>To print the title you need to induce <em>WebDriverWait</em> either for either of the following expected_conditions:</p> <ul> <li><a class="external-link" href="https://seleniumhq.github.io/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html#selenium.webdriver.support.expected_conditions.title_contains" rel="nofollow noreferrer"><code>title_contains(partial_title)</code></a></li> <li><a class="external-link" href="https://seleniumhq.github.io/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html#selenium.webdriver.support.expected_conditions.title_is" rel="nofollow noreferrer"><code>title_is(title)</code></a></li> <li><p>An example:</p> <pre><code>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 options = webdriver.ChromeOptions() options.add_argument("start-maximized") options.add_argument('disable-infobars') driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe') driver.get("https://www.google.com/") WebDriverWait(driver, 10).until(EC.title_contains("G")) print("Page title is: %s" %(driver.title)) </code></pre></li> <li><p>Console Output:</p> <pre><code>Page title is: Google </code></pre></li> </ul></div> <div class="mb0"> <div class="mt16 grid gs8 gsy fw-wrap jc-end ai-start pt4 mb16"> <div class="grid--cell mr16 fl1 w96"></div> <div class="post-signature grid--cell"> <div class="s-user-card s-user-card"> <time class="s-user-card--time" datetime="answered Dec 22 '18 at 11:51">answered Dec 22 '18 at 11:51</time> <a href="../../users/7429447/undetected-selenium" class="s-avatar s-avatar__32 s-user-card--avatar"> <img class="s-avatar--image" src="../../users/profiles/7429447.webp" data-jdenticon-width="32" data-jdenticon-height="32" data-jdenticon-value="undetected Selenium" /> </a> <div class="s-user-card--info"> <a href="../../users/7429447/undetected-selenium" class="s-user-card--link">undetected Selenium</a> <ul class="s-user-card--awards"> <li class="s-user-card--rep" title="reputation score">183,867</li> <li class="s-award-bling s-award-bling__gold" title="41 gold badges">41</li> <li class="s-award-bling s-award-bling__silver" title="278 silver badges">278</li> <li class="s-award-bling s-award-bling__bronze" title="352 bronze badges">352</li> </ul> </div> </div> </div> </div> </div> </div> <div class="post-layout--right js-post-comments-component"> </div> </div> </div> </div> </div> <div id="sidebar" class="show-votes" role="complementary" aria-label="sidebar"> <div class="module sidebar-linked"> <h4 id="h-linked">Linked</h4> <div class="linked"> <div class="spacer"> <a title="Vote score (upvotes - downvotes)"><div class="answer-votes default">0</div></a> <a href="../../questions/51955896/how-to-catch-network-failures-while-invoking-get-method-through-selenium-and-p" class="question-hyperlink">How to catch network failures while invoking get() method through Selenium and Python?</a> </div> </div> </div> </div> </div> </div> <script src="../../static/js/stack-icons.js"></script> <script src="../../static/js/fromnow.js"></script> </body> </html>