无法找到元素Selenium webdriver ||蟒蛇

时间:2018-04-19 13:30:47

标签: python selenium selenium-webdriver

<div class="container-fluid ">
<div class="navbar-header">
<span id="problem_hide_search" class="nav navbar-left">
<span id="ca660735dba5d3003d7e5478dc9619b2_title" class="list_search_title navbar-text " style="float: left; display:inherit">Go to</span>
<div style="float: left; display:inherit">
<div class="input-group" style="width: 300px;">
<span class="input-group-addon input-group-select">
<label class="sr-only" for="ca660735dba5d3003d7e5478dc9619b2_text">Search</label>
<input id="ca660735dba5d3003d7e5478dc9619b2_text" class="form-control" name="ca660735dba5d3003d7e5478dc9619b2_text" style="width: 150px;" placeholder="Search"/>
</div>
</div>
<script data-comment="widget search load event">addLoadEvent(function () { new GlideWidgetSearch('ca660735dba5d3003d7e5478dc9619b2', 'problem', 'true'); });</script>

尝试通过切换到iframe并按

选择来找到搜索框
search_box = driver.find_element_by_xpath('//*@id="ca660735dba5d3003d7e5478dc9619b2_text"]')

但我收到错误无法找到消息:没有这样的元素:无法找到元素: 甚至以为我找到了一个匹配的节点。

1 个答案:

答案 0 :(得分:0)

正如您在问题中提到的那样,您尝试按照最佳做法切换到iframe并选择来找到搜索框:

  • WebDriverWait frame 可以切换,如下所示:

    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.ID,"id_of_iframe"))
    

    在这里,您将找到详细的讨论How can I select a html element no matter what frame it is in in selenium?

  • 当您在<iframe>标记中查找具有正确expected_conditions WebDriverWait 时的元素。考虑到您打算向元素发送文本这一事实,您可以使用以下代码行:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='navbar-header']//input[@class='form-control' and contains(@id,'_text')]"))).send_keys("hello")
    
相关问题