0

Edited based on the answers:

I am using Selenium with Python and trying to locate a button on an web application on Chrome. The block of code has an iframe as mentioned in the answer.

<iframe data-bind="attr: { src: src, foo: $root.registerTargetDisplayFrame($data, $element) }, event: {load: function() {loaded(true);}, focus: $root.blurredNavigationPane}" src="https://products.com/InfoShareAuthor/home">
  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
      <html>
        <head>code here
        <frameset id="IshTop" class="infoshareauthor" framespacing="0" border="0" bordercolor="#FFFFFF" frameborder="0" rows="31,25,*,0">
           <frame id="MenuBar" scrolling="no" name="MenuBar" src="./MainMenuBar.asp">
             <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
               <html>
                 <head>
                 <body>
                   <div id="Top-Menu-Container">
                      <div id="top-menu-wrapper">
                         <div id="top-menu">
                            <form name="MainBar">
                               <script type="text/javascript" language="javascript">
                               <table cellspacing="0" cellpadding="0" border="0">
                                 <tbody>
                                    <tr>
                                       <td width="95" valign="bottom">
                                       <td width="95" valign="bottom">
                                          <div style="POSITION: relative;">
                                              <div height="30" style="POSITION: absolute; z-index:0; top: 4px; margin-left: -5px">
                                                 <a href="javascript:TabSelect(1);">
                                                    <img border="0" src="./UIFramework/tab_active.png">
                                                 </a>
                                              </div>
                                              <div onclick="javascript:TabSelect(1);" style="POSITION: absolute; z-index:2; top: -8px">
                                                 <table cellspacing="0" cellpadding="0" border="0">
                                                     <tbody>
                                                         <tr>
                                                            <td id="MenuButton1" class="tab_active" width="95" valign="bottom" height="30" align="center" style="cursor:pointer;padding-bottom:2px;" name="Repository">Repository</td>
                                                         </tr>
                                                     </tbody>
                                                 </table>
                                              </div>
                                            </div>
                                          </td>
                                          <td width="95" valign="bottom">
                                          <td width="95" valign="bottom">
                                          <td width="95" valign="bottom">
                                          <td width="95" valign="bottom">
                                        </tr>
                                    </tbody>
                                 </table>
                               </form>
                            </div>
                            <div id="top-help">
                            <div id="top-nav-links">
                          </div>
                        </div>
                   </body>
             </html>
       </frame>
         <frame id="BreadCrumbs" frameborder="0" border="0" scrolling="no" name="BreadCrumbs" src="./BreadCrumbs.asp">
         <frameset id="Application" bordercolor="#0099CC" frameborder="0" rows="0,*,0,0,0,0">
         <frameset id="HiddenFrameSet" bordercolor="#0099CC" frameborder="0" rows="0,0,,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1">
      <noframes> It looks like your browser doesn't support frames. This page requires frames in order to function. <br><br>For more information, please <a href='http://www.trisoftcms.com/en/contact-us.html' target=_blank style='white-space:nowrap'>contact us</a>. </noframes>
   </frameset>
  </html>
</iframe>

I switched frames using this:

iframe = browser.find_element_by_xpath("//iframe[@src='https://products.com/InfoShareAuthor/home']")
browser.switch_to.frame(iframe)

The code that I wrote:

browser.find_element_by_xpath("//td[@id='MenuButton1'][@name='Repository'][contains(text(),'Repository')]")

I could find the element using this xpath when I did a Firebug search

I also tried:

browser.find_element_by_id("MenuButton1")

and

browser.find_element_by_name("Repository")

Note: When I click the button, the URL does not change. Just a list of items in the application expands. Also, IDs and the Names are unique for the seven five menu buttons. None of the menu buttons work.

Does any one have any idea about what might be wrong? I am very new to Python and Selenium.

  • [`Waits`](http://selenium-python.readthedocs.io/waits.html#waits) – JRodDynamite Mar 23 '17 at 07:03
  • ^ OR the button may be [inside an iframe](http://stackoverflow.com/a/24247565/2689986). – shad0w_wa1k3r Mar 23 '17 at 07:04
  • There are various reasons why your code is not working, it can synchronization issue where page is still loading, you can you explicit wait to handle it, or the element is inside a iframe or element is nested with another element etc, So try with explict wait & even after it does not work share few more lines of html above it – thebadguy Mar 23 '17 at 07:30
  • Try to click on button using `java-script executor` method – Jainish Kapadia Mar 23 '17 at 07:56
  • 1
    Can you share site url? – Jainish Kapadia Mar 23 '17 at 09:14
  • I already used Implicit Wait and Wait is not the issue. I do see iframes in the code and I am exploring that aspect. Will check the java-script executor method as well in case iframes do not work. I wish I could share the URL, that is an internal site, unfortunately. – Avishekh Das Mar 23 '17 at 09:45
  • Hi All, I edited my question and pasted a bigger chunk of code with iframes. Still unable to find the element. Let me know if you need more details. – Avishekh Das Mar 24 '17 at 05:52
  • @AvishekhDas, try to run `browser.execute_script("javascript:TabSelect(1);")` before the statement `browser.find_element_by_id("MenuButton1")` – dot.Py Mar 24 '17 at 10:29
  • @dot.Py I get this error. Message: unknown error: TabSelect is not defined – Avishekh Das Mar 24 '17 at 12:48

2 Answers2

0

you can try load iframe url. It avoids issues with selenium waiting from the iframe to load

Felix Martinez
  • 339
  • 2
  • 3
0

This doesn't exactly answer your question, but it does address what you're trying to do: it is likely you can accomplish the same task (and many others) with SDL's API client ISHRemote.

https://github.com/sdl/ISHRemote

For example, if you're looking for all the directories under '\General':

Import-Module ISHRemote
# first authenticate
$session = New-IshSession -IshPassword $password -IshUserName $username -WsBaseUrl 'https://ccms.example.com/InfoShareWS/'
# get a list of all the child folders under General
Get-IshFolder -IshSession $session -FolderPath '\General' -Recurse -Depth 2

Or if you're trying to get a list of files in a particular directory:

Import-Module ISHRemote    
# first authenticate
$session = New-IshSession -IshPassword $password -IshUserName $username -WsBaseUrl 'https://ccms.example.com/InfoShareWS/'
# get all content in this folder
Get-IshFolderContent -IshSession $session -FolderPath 'General\path\to\topics'

With ISHRemote, you can also find and update publications, move content, modify metadata, etc.

Hope that helps.

tintinno
  • 16
  • 2