humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | Changelog

get_all_by_id

get_all_by_id($id,$exactly=false,$frame="-1"); - id

:

  • $id id
  • $exactly ? /

    :
  • ()
  • -1

    <?php
    
    // Scenario: Get all elements by ID from a collection
    // Description: This example demonstrates how to get a collection of elements and then find all elements with a specific ID within that collection
    // Classes used: XHEInterfaces, XHEDiv, XHEBrowser, XHEApplication
    
    // Connection string to XHE API
    $xhe_host = getenv("RPABOT_HOST_URL");
    
    // Path to init.php file
    if (!isset($path))
    {
        // Path to init.php file for connecting to XHE API
        $path = "../../../Templates/init.php";
        // When connecting init.php file, all functionality of classes for working with XHE API will be available
        require($path);
    }
    
    // Navigate to the polygon page if the page was not loaded earlier
    WEB::$browser->navigate(TEST_POLYGON_URL . "divs.html");
    
    // Example: Get all div elements and then find all divs with a specific ID within that collection
    
    // Get all div elements on the page
    $divs = DOM::$div->get_all();
    
    // Check that we have found at least one div
    if ($divs->count() > 0)
    {
        echo "Found " . $divs->count() . " div elements\n";
        
        // Try to find all divs with a specific ID
        $targetId = "example";
        $divsById = $divs->get_all_by_id($targetId);
        
        // Check if any divs with the specified ID were found
        if ($divsById->count() > 0)
        {
            echo "\nFound " . $divsById->count() . " div elements with ID '" . $targetId . "':\n";
            
            // Process each found div
            for ($k = 0; $k < $divsById->count(); $k++)
            {
                $currentDiv = $divsById->get($k);
                
                if ($currentDiv && $currentDiv->is_exist())
                {
                    echo "\nDiv #" . ($k + 1) . " with ID '" . $targetId . "':\n";
                    echo "Div inner text: " . $currentDiv->get_inner_text() . "\n";
                    echo "Div inner number: " . $currentDiv->inner_number . "\n";
                }
            }
        }
        else
        {
            echo "\nNo div elements with ID '" . $targetId . "' found in the collection\n";
        }
        
        // Try to find all divs with another ID
        $targetId2 = "test";
        $divsById2 = $divs->get_all_by_id($targetId2);
        
        // Check if any divs with the specified ID were found
        if ($divsById2->count() > 0)
        {
            echo "\nFound " . $divsById2->count() . " div elements with ID '" . $targetId2 . "':\n";
            
            // Process each found div
            for ($k = 0; $k < $divsById2->count(); $k++)
            {
                $currentDiv = $divsById2->get($k);
                
                if ($currentDiv && $currentDiv->is_exist())
                {
                    echo "\nDiv #" . ($k + 1) . " with ID '" . $targetId2 . "':\n";
                    echo "Div inner text: " . $currentDiv->get_inner_text() . "\n";
                    echo "Div inner number: " . $currentDiv->inner_number . "\n";
                }
            }
        }
        else
        {
            echo "\nNo div elements with ID '" . $targetId2 . "' found in the collection\n";
        }
        
        // Try to find all divs with a non-existent ID
        $nonExistentId = "nonexistent";
        $divsByNonExistentId = $divs->get_all_by_id($nonExistentId);
        
        // Check if any divs with the non-existent ID were found
        if ($divsByNonExistentId->count() > 0)
        {
            echo "\nUnexpectedly found " . $divsByNonExistentId->count() . " div elements with ID '" . $nonExistentId . "'\n";
        }
        else
        {
            echo "\nAs expected, no div elements with ID '" . $nonExistentId . "' found in the collection\n";
        }
        
        // Display all div IDs in the collection for reference
        echo "\nAll div IDs in the collection:\n";
        for ($k = 0; $k < $divs->count(); $k++)
        {
            $currentDiv = $divs->get($k);
            
            if ($currentDiv && $currentDiv->is_exist())
            {
                $divId = $currentDiv->get_id();
                $divInnerText = $currentDiv->get_inner_text();
                $divClass = $currentDiv->get_attribute("class");
                
                echo "Div #" . ($k + 1) . ": ID = '" . $divId . "', Class = '" . $divClass . "', Text = '" . $divInnerText . "'\n";
            }
        }
    }
    else
    {
        echo "No div elements found on the page\n";
    }
    
    // Stop the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7010"
    from xweb_human_emulator import *
    
    # 
    echo("<hr><font color=blue>interfaces.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1.    : ")
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html"),"<br>")
    
    # 2 
    echo("2.    : ")
    anchors=anchor.get_all()
    echo(anchors.get_count(),"<br>")
    
    # 3 
    echo("3.      id,  id : <br>")
    anchors_1=anchors.get_all_by_id("id")
    print(anchors_1.get_inner_text())
    
    # 4 
    echo("4.      id = seonote_id : <br>")
    anchors_2=anchors.get_all_by_id("seonote_id",true)
    print(anchors_2.get_inner_text())
    
    # 
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = Environment.GetEnvironmentVariable("RPABOT_HOST_URL");
    			InitXHE();
    
    			// 
    			echo("<hr><font color=blue>interfaces.get_all_by_id</font><hr>");
    							
    			// 1 
    			echo("1.    : ");
    			echo(browser.navigate("rpa-bot.ru/wiki/poligon/anchor.html")+"<br>");
    
    			// 2 
    			echo("2.    : ");
    			XHEInterfaces anchors=anchor.get_all();
    			echo(anchors.get_count()+"<br>");
    
    			// 3 
    			echo("3.      id,  id : \n\n");
    			XHEInterfaces anchors_1=anchors.get_all_by_id("id");
    			echo(anchors_1.get_inner_text());
    
    			// 4 
    			echo("\n4.      id = seonote_id : \n\n");
    			XHEInterfaces anchors_2=anchors.get_all_by_id("seonote_id",true);
    			echo(anchors_2.get_inner_text());
    
    			// 
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    //   ,    
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // 
    echo("<hr><font color=blue>interface.get_all_by_id</font><hr>");
    
    // 1 
    echo("1.    : ");
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"<br>");
    
    // 2 
    echo("2.    : ");
    anchors=anchor.get_all();
    echo(anchors.get_count()+"<br>");
    
    // 3 
    echo("3.      id,  id : \n\n");
    anchors_1=anchors.get_all_by_id("id");
    echo(anchors_1.get_inner_text());
    
    // 4 
    echo("\n4.      id = seonote_id : \n\n");
    anchors_2=anchors.get_all_by_id("seonote_id",true);
    echo(anchors_2.get_inner_text());
    
    // 
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Interfaces        DOM  System  Vision  Web  Window        
    =============================================
    - , .