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

ensure_visible

ensure_visible($smooth=false,$side="start"); - скролировать страницу, используя прокрутку браузера так, чтобы элемент был виден прямо сейчас (доступна с верси 4.9.40)

  • $smooth=false - делаем прокрутку скрола плавно или нет. По умолчанию не плавно.
  • С версии Human Emulator Studio 7.0.52 в функцию добавлен параметр side, принимающий значения "start", "center","end" или "nearest" для указания места, где будет показан элемент. После отработки функция возвращает результат своей работы в скрипт (тип возвращаемого значения boolean):
  • true – выполнили успешно
  • false – найти такой элемент не удалось (например нет вообще элементов, удовлетворяющих заданным критериям или нет такого фрейма)

    Пример использования
    <?php
    
    // Scenario: For the current page, find a DOM element and ensure that this element falls into the visible area of the page
    // Description: For the current page, find a DOM element <a> and ensure that this element falls into the visible area of the page
    // Classes used: XHEAnchor, XHEInterface, XHEBrowser, XHEApplication
    
    // Connection string to XHE API
    $xhe_host = "localhost:7010";
    
    // Path to init.php file
    if (!isset($path))
    {
        // Path to init.php file for connecting to XHE API
        $path = "../../../Templates/init.php";
        // When connecting the 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 . "anchor.html");
    
    // Example 1: Get the anchor object by serial number 1 among inputs of this type and ensure that this element falls into the visible area of the page.
    
    // Get the anchor object by serial number 1 among inputs of this type and get it as XHEInterface.
    $targetAnchor = DOM::$anchor->get_by_number(1);
    
    // Check that the DOM element is received
    if ($targetAnchor->inner_number != -1)
    {
        // For the found anchor, execute the command and get the method execution result as a variable.
        // The execution result will be assigned to a variable of type bool.
        // If the variable value is true, then the DOM element is in the visible area of the Browser page.
        // If the variable value is false, then the DOM element is not in the visible area of the Browser page.
        $elementIsVisibled = $targetAnchor->ensure_visible();
    }
    
    // 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>interface.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Перейдем на полигон : ")
    echo(browser.navigate("http://rpa-bot.ru/wiki/"),"<br>")
    
    # 2 
    echo("2. Виден ли с нулевым номером : ")
    echo(anchor.get_by_number(0).is_view_now(),"<br>")
    
    # 3 
    echo("3. Виден ли 100 anchor : ")
    if not anchor.get_by_number(100).is_view_now():
    	echo("не виден<br>")
    
    # 4
    echo("4	. Покажем 100 номер : ")
    echo(anchor.get_by_number(100).ensure_visible(),"\n")
    
    # 5
    echo("5. Виден ли 100 anchor : ")
    echo(anchor.get_by_number(100).is_view_now())
    
    # конец
    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 = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>interface.ensure_visible</font><hr>");
    										
    			// 1 шаг
    			echo("1. Перейдем на полигон : ");
    			echo(browser.navigate("https://rpa-bot.ru/wiki")+"<br>");
    			
    			// 2 шаг
    			echo("2. Просматривается ли 0 anchor : ");
    			echo(anchor.get_by_number(0).is_view_now()+"<br>");
    			
    			// 3 шаг
    			echo("3. Просматривается ли 100 anchor : ");
    			if (!anchor.get_by_number(100).is_view_now())
    				echo("не виден<br>");
    
    			// 4 шаг
    			echo("4. Сделаем 100 anchor просмариваемым : ");
    			echo(anchor.get_by_number(100).ensure_visible()+"\n");
    
    			// 5 шаг
    			echo("5. Просматривается ли 100 anchor : ");
    			echo(anchor.get_by_number(100).is_view_now());
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>anchor.ensure_visible</font><hr>");
    
    // 1 шаг
    echo("1. Перейдем на полигон : ");
    echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"\n");
    // 2 шаг
    echo("2. Вызовем метод ensure_visible : \n");
    var result = anchor.ensure_visible(false, "start");
    echo(result+"\n");
    
    // конец
    echo("\n");
    
    // уведомляем среду что скрипт закончил работать
    app.quit();

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