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

get_by_inner_text

get_by_inner_text($inner_text,$exactly=true); - Получить интерфейс по внутреннему тексту

Функция на вход принимает параметры:

  • $inner_text – значение внутреннего текста
  • $exactly – Требуется точное соответствие значения? Да/Нет

    После выполнения функции возвращаемое значение будет равно одному из двух :
  • результат – интерфейс или false - если найти не удалось

    Пример использования
    <?php
    
    // Scenario: Get elements by inner text from a collection
    // Description: This example demonstrates how to get a collection of elements and then find specific elements by their inner text within that collection
    // Classes used: XHEInterfaces, XHEAnchor, 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 . "anchors.html");
    
    // Example: Get all anchor elements and then find specific anchors by their inner text within that collection
    
    // Get all anchor elements on the page
    $anchors = DOM::$anchor->get_all();
    
    // Check that we have found at least one anchor
    if ($anchors->count() > 0)
    {
        echo "Found " . $anchors->count() . " anchor elements\n";
        
        // Try to find an anchor with a specific inner text (exact match) in anchor elements
        $targetText = "Example Link";
        $anchorByText = $anchors->get_by_inner_text($targetText, true);
        
        // Check if the anchor with the specified inner text was found in anchor elements and exists
        if ($anchorByText && $anchorByText->is_exist())
        {
            echo "\nFound anchor with inner text '" . $targetText . "' (exact match):\n";
            echo "Anchor href: " . $anchorByText->get_href() . "\n";
            echo "Anchor inner number: " . $anchorByText->inner_number . "\n";
        }
        else
        {
            echo "\nNo anchor with inner text '" . $targetText . "' (exact match) found in the collection\n";
        }
        
        // Try to find an anchor with a partial inner text match in anchor elements
        $partialText = "Link";
        $anchorByPartialText = $anchors->get_by_inner_text($partialText, false);
        
        // Check if the anchor with the partial inner text was found in anchor elements and exists
        if ($anchorByPartialText && $anchorByPartialText->is_exist())
        {
            echo "\nFound anchor with partial inner text '" . $partialText . "':\n";
            echo "Anchor href: " . $anchorByPartialText->get_href() . "\n";
            echo "Anchor inner number: " . $anchorByPartialText->inner_number . "\n";
            echo "Full inner text: " . $anchorByPartialText->get_inner_text() . "\n";
        }
        else
        {
            echo "\nNo anchor with partial inner text '" . $partialText . "' found in the collection\n";
        }
    
        // Try to find an anchor with another inner text
        $targetText2 = "Test";
        $anchorByText2 = $anchors->get_by_inner_text($targetText2, true);
        
        // Check if the anchor with the specified inner text was found
        if ($anchorByText2 && $anchorByText2->is_exist())
        {
            echo "\nFound anchor with inner text '" . $targetText2 . "':\n";
            echo "Anchor href: " . $anchorByText2->get_href() . "\n";
            echo "Anchor inner number: " . $anchorByText2->inner_number . "\n";
            
            // Add a new attribute to the found anchor
            $attrResult = $anchorByText2->set_attribute("data-found", "true");
            
            if ($attrResult)
            {
                echo "Successfully added data-found attribute to the anchor\n";
            }
            else
            {
                echo "Failed to add attribute to the anchor\n";
            }
        }
        else
        {
            echo "\nNo anchor with inner text '" . $targetText2 . "' found in the collection\n";
        }
        
        // Try to find an anchor with a non-existent inner text in anchor elements
        $nonExistentText = "NonExistentLink";
        $anchorByNonExistentText = $anchors->get_by_inner_text($nonExistentText, true);
        
        // Check if the anchor with the non-existent inner text was found in anchor elements and exists
        if ($anchorByNonExistentText && $anchorByNonExistentText->is_exist())
        {
            echo "\nUnexpectedly found anchor with inner text '" . $nonExistentText . "'\n";
        }
        else
        {
            echo "\nAs expected, no anchor with inner text '" . $nonExistentText . "' found in the collection\n";
        }
        
        // Display all anchor inner texts in the collection for reference
        echo "\nAll anchor inner texts in the collection:\n";
        for ($k = 0; $k < $anchors->count(); $k++)
        {
            $currentAnchor = $anchors->get($k);
            
            if ($currentAnchor && $currentAnchor->is_exist())
            {
                $anchorInnerText = $currentAnchor->get_inner_text();
                $anchorHref = $currentAnchor->get_href();
                
                echo "Anchor #" . ($k + 1) . ": Text = '" . $anchorInnerText . "', Href = '" . $anchorHref . "'\n";
            }
        }
    }
    else
    {
        echo "No anchor 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. Получим размеры ссылки с текстом = ссылка onmouseover : ")
    onmouseover_anchor=anchors.get_by_inner_text("ссылка onmouseover")
    echo(onmouseover_anchor.get_width()," x ")
    echo(onmouseover_anchor.get_height(),"<br>")
    
    # 4 
    echo("4. Получим размеры ссылки с текстом, содержащей SEO : ")
    onmouseover_anchor=anchors.get_by_inner_text("SEO",false)
    echo(onmouseover_anchor.get_width()," x ")
    echo(onmouseover_anchor.get_height(),"<br>")
    
    # конец
    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_by_inner_text</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. Получим размеры ссылки с текстом = ссылка onmouseover : ");
    			XHEInterface onmouseover_anchor=anchors.get_by_inner_text("ссылка onmouseover");
    			echo(onmouseover_anchor.get_width()+" x "+onmouseover_anchor.get_height()+"<br>");
    
    			// 4 шаг
    			echo("4. Получим размеры ссылки с текстом, содержащей SEO : ");
    			XHEInterface seo_anchor=anchors.get_by_inner_text("SEO",false);
    			echo(seo_anchor.get_width()+" x "+seo_anchor.get_height()+"<br>");
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // IE + Chrom
    
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>interface.get_by_inner_text</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. Получим размеры ссылки с текстом = ссылка onmouseover : ");
    onmouseover_anchor=anchors.get_by_inner_text("ссылка onmouseover");
    echo(onmouseover_anchor.get_width()+" x "+onmouseover_anchor.get_height()+"<br>");
    
    // 4 шаг
    echo("4. Получим размеры ссылки с текстом, содержащей SEO : ");
    onmouseover_anchor=anchors.get_by_inner_text("SEO",false);
    echo(onmouseover_anchor.get_width()+" x "+onmouseover_anchor.get_height()+"<br>");
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Interfaces    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.