1

I am trying to navigate to a search box and send_keys with selenium python but completely stuck.

And here is the source code snippet:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<div id="LeftTreeFrame" class="leftNavBackground" >
    <div class="ui-widget searchPanelContainer">
        <div id="searchPanel" class="search-field-container search-field-container-margin">
            <input type="text" doesntDirty id="Search" name="Search" class="search-text-field-left-tree-frame" NoHighlight="nohighlight"/>
            <div class="search-field-icon-container">
                <a id="searchlbl" href="#"><img src="../images/normal_search_u39.svg" title="Go To Page" /></a>
            </div>
        </div>
    </div>
    <div id='pageNavigation'>
        <div id='ootbNavigationPage'></div>
        <div id='favoriteNavigationPage'></div>
        <div id='adminNavigationPage'></div>
        <div id='navigationEmptyState' class="treeEmptyState">
            <div class="message"></div>
            <a href="#" onclick="configureFavorites()"></a>
        </div>
    </div>
    <div class="navigation-view-mode-container">
        <div class="box" onclick="renderModel(0)">
            <button  type="button">
                <span class="svg-load ootb-icon" data-src="~/images/Reskin/ootb-icon.svg"></span>
            </button>
        </div>
        <div class="star" onclick="renderModel(1)">
            <button  type="button">
                <span class="svg-load star-icon" data-src="~/images/Reskin/star.svg"></span>
            </button>
        </div>
        <div class="person" onclick="renderModel(2)">
            <button  type="button">
                <span class="svg-load person-icon" data-src="~/images/Reskin/person-nav.svg"></span>
            </button>
        </div>
    </div>
</div>

When I try to do

element = driver.find_element(By.XPATH, '//input[@name="Search"]')
element.send_keys('test')

I get error "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable"

I have tried everything I can imagine, but cannot click the element or send keys.

Also, this page is a new page that opens after the last successful click. I first tried switching to this page by

#printing handles 
handles = driver.window_handles
i=0
for handle in handles:
    print(f"Handle {i}: {handle}\n")
    i +=1

#after confirming new page is second handle via:

 driver.switch_to.window(handles[1]) 
    
    print(f" Title: {driver.title}")
    
    print(f" Current url: {driver.current_url}")
    print('\n')

#I can even find the tag I am looking for after switching to new window:

all_div_tags = driver.find_elements(By.TAG_NAME, "input")

for tag in all_div_tags:

    print(f"Attribute name: {tag.get_attribute('name')}\n")

#but i cannot get to the search box. Thank you in advance!

JonR23
  • 11
  • 2

1 Answers1

0

Look at the html code, notice that //input[@name="Search"] is contained in an <iframe>. In order to select an element inside an iframe with find_element() you have first to switch to the iframe, as shown in the code

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "frmCode")))

element = driver.find_element(By.XPATH, '//input[@name="Search"]')
...
sound wave
  • 3,191
  • 3
  • 11
  • 29