I am trying to delete a <div>
section using
Robot Framework. How can I do that ? Also, Is there a way to modify
the class
within a <div>
?
e.g. <div name="test" class="..">
. I’m trying
to either delete the whole <div>
section or
clear the class elements.
ベストアンサー
要素の削除
ロボットやSeleniumLibraryのいずれもページに項目を追加したり削除したりすることはできませんが、 javascriptを実行キーワードを使用してjavascriptを実行してください。
たとえば、 “page-footer”というIDのdivを削除するには、次のようにします:
execute JavaScript
... var element=document.querySelector('#page-footer');
... element.parentNode.removeChild(element);
ページからフッターを削除する完全な実例があります:
*** Variables ***
${browser} chrome
*** Settings ***
Library Selenium2Library
Suite Setup open browser about:blank ${browser}
Suite Teardown close all browsers
*** Test cases ***
Example
[Setup] go to https://the-internet.herokuapp.com/broken_images
# verify the footer is there
page should contain Powered by Elemental Selenium
# remove it
execute JavaScript
... var element=document.querySelector('#page-footer');
... element.parentNode.removeChild(element);
# verify it was removed
page should not contain Powered by Elemental Selenium
クラスを変更する
クラスまたは他の属性を変更するには、同じテクニックを使用して、要素の setAttribute
メソッドを呼び出すことができます。
たとえば、次のようにクラスをページフッターの “new_class”に設定します。
execute JavaScript
... var element=document.querySelector('#page-footer');
... element.setAttribute("class", "new_class");