Can I use SeleniumBase built-in methods to add elements directly to the page? #1429
Answered
by
mdmintz
chenqinggang001
asked this question in
Q&A
-
I want to add |
Beta Was this translation helpful? Give feedback.
Answered by
mdmintz
Jul 23, 2022
Replies: 1 comment 1 reply
-
You'll need to use JavaScript to do that. https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement Eg: from seleniumbase import BaseCase
class AddButtonTest(BaseCase):
def test_add_button(self):
script_to_add_button = """function injectButton() {
var new_button=document.createElement('button');
document.getElementsByTagName('body')[0].appendChild(new_button);
new_button.style="width: 200px; height: 120px";
}
injectButton();"""
self.execute_script(script_to_add_button)
self.sleep(3) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mdmintz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need to use JavaScript to do that. https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
With SeleniumBase you can call
self.execute_script(JS)
to execute the JavaScript that you need to create elements.Eg: