Created
October 7, 2019 20:59
-
-
Save aaltat/f9c1aa8f7871913b09ff625296128513 to your computer and use it in GitHub Desktop.
Input field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.action_chains import ActionChains | |
driver = webdriver.Chrome() | |
driver.get('file:///path/to/page.html') | |
element = driver.find_element_by_id('text_field') | |
action = ActionChains(driver) | |
for text in ['AA', 'BB', 'CC']: | |
action.send_keys_to_element(element, text) | |
action.perform() | |
button = driver.find_element_by_id('OK') | |
button.click() | |
new_element = driver.find_element_by_xpath('//div/p') | |
text = new_element.text | |
print(text) | |
try: | |
assert text == 'AABBCC', 'Text is not equal' | |
finally: | |
driver.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<body> | |
<p>Please input text and click the button. Text will appear in the page.</p><br> | |
<input id="text_field" size="30" type="text" /><br><br> | |
<button id="OK" onclick="getText();">OK</button><br> | |
<div id="div1"></div> | |
</body> | |
<script> | |
function getText() { | |
var input = document.getElementById("text_field").value; | |
var para = document.createElement("p"); | |
var node = document.createTextNode(input); | |
para.appendChild(node); | |
var element = document.getElementById("div1"); | |
element.appendChild(para); | |
} | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment