0

I have a submenu item that I used to be able to access via selenium web navigation. Now I keep getting the following error: "You may only interact with visible elements". I have tried a number of recommendations (waits, implicit/explicit, maximizing windows, using the ActionChain object) without success. Can anyone spot why this element would remain invisible by looking at the following HTML and code?:

        <ul class="nav" >
             <li>
                <a href="/edc">EDC</a>
            </li>
        </ul>


        <ul class="nav" >
            <li>
                <a href="/qa/main">Queries</a>
            </li>
        </ul>


        <ul class="nav" >
            <li>
                <a href="/docs">Docs</a>
            </li>
        </ul>


        <ul class="nav" >
            <li>
                <a href="/data">Data</a>
            </li>
        </ul>


        <ul class="nav" >
            <li>
                <a href="/aal/main">Audit Log</a>
            </li>
        </ul>


        <ul class="nav" >
            <li>
                <a href="/summaries/main">Reports</a>
            </li>
        </ul>


        <ul class="nav" >
            <li class="dropdown ">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">Tools <b class="caret"></b></a>
                <ul class="dropdown-menu">

            <li>
                <a href="/sql">SQL Worksheet</a>
            </li>
            <li>
                <a href="/meddra">Meddra</a>
            </li>
            <li>
                <a href="/sae">SAE</a>
            </li>
            <li>
                <a href="/pdf">Worksheets</a>
            </li>
            <li>
                <a href="/pipelines/report">Pipelines</a>
            </li>
            <li>
                <a href="/tools/sync">Sync</a>
            </li>
            <li>
                <a href="/db">Project Management</a>
            </li>
            <li>
                <a href="/rss">RSS</a>
            </li>
            <li>
                <a href="/ipt/main">IPT</a>
            </li>
            <li>
                <a href="/images/main">Images</a>
            </li>
        </ul>
    </li>
</ul>

And here is the python code snippet that is not working:

try:
    menu_item = driver.find_element(By.LINK_TEXT, 'Tools')
    actions = ActionChains(driver)
    actions.click(menu_item).perform()

except Exception as error:
    print ("Tools menu not found: " + str(error))

try:
    wait = WebDriverWait(driver, 10) wait.until(EC.presence_of_element_located(By.XPATH("/html/body/header/div/div/div/div/ul[7]/li/ul/li[9]/a")));
    ipt_menu_item = driver.find_element(By.XPATH, "/html/body/header/div/div/div/div/ul[7]/li/ul/li[9]/a")
    actions.click(ipt_menu_item).perform()

except Exception as error:
    print ("Tools | IPT link not found: "  + str(error))
5
  • can you give the whole url of the page? Commented Dec 19, 2017 at 18:36
  • No it requires authentication to access this page. However if you have a suspicion that some other element might be blocking this from working, I would be happy to try that out. Commented Dec 19, 2017 at 22:08
  • Sometimes elements being inside iframes causes funky stuff to happen. Worth checking Commented Dec 19, 2017 at 22:09
  • Thanks SuperStew. No IFrames on this page though. Commented Dec 19, 2017 at 22:14
  • Does the element have a display attribute? Commented Dec 19, 2017 at 22:19

1 Answer 1

1

I have dealt with this same issue a few times, I have found that most the time you can move to the element first and then issue the .click() command:

Element = driver.find_element_by_link_text('link')
actions = ActionChains(driver)
# try this
actions.move_to_element(Element)
# or this
driver.execute_script("return arguments[0].scrollIntoView();", Element)
Element.click()

EDIT: Or, a third option for click in case the top two do not work, if you can get the element with selenium and the element is in view, but just can't interact with it, then it's probably behind a <div that is not visible. Try this click instead of your normal .click():

driver.execute_script("arguments[0].click()", Element)

If that does not work, you may need to try interacting with the attributes to get the element in a state of visibility for selenium before you make the click, such as:

driver.execute_script("arguments[0].style.display = 'block'", Element)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for responding so quickly PixelEinstein. I tried both solutions and unfortunately am getting the same error. I am using selenium server 3.8 and the HTMLUNITWITHJS driver remotely. Locally I use gecko driver 0.19.1 and Firefox 57.0.1
Interesting, when you run this line: wait = WebDriverWait(driver, 10) wait.until(EC.presence_of_element_located(By.XPATH("/html/body/header/div/div/div/div/ul[7]/li/ul/li[9]/a"))) Does it complete the wait?

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.