1
<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>

Am trying to locate the Search box by switching into iframe and selecting by

search_box = driver.find_element_by_xpath('//*@id="ca660735dba5d3003d7e5478dc9619b2_text"]')

But i get error unable to locate Message: no such element: Unable to locate element: Even thought I find one matching node.

Andersson
  • 51,635
  • 17
  • 77
  • 129
Nav
  • 71
  • 8
  • *find one matching node*... Where did you find it? Also let us know whether absent of opening bracket in predicate is a simple typo – Andersson Apr 19 '18 at 13:50

1 Answers1

0

As you mentioned in your question that you are trying to locate the Search box by switching into iframe and selecting as per the best practices you should :

  • Induce WebDriverWait for the frame to be available to switch as follows :

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

    Here you will find a detailed discussion How can I select a html element no matter what frame it is in in selenium?

  • While you look out for an element within an <iframe> tag induce WebDriverWait with proper expected_conditions. Considering the fact that you intend to send text to the element you can use the following line of code :

    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")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352