Last active
December 16, 2015 12:29
-
-
Save bebef1987/5434882 to your computer and use it in GitHub Desktop.
sel test
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> | |
<body> | |
<ul id="myList"> | |
<li>Coffee | |
<ul> | |
<li>element 2</li> | |
<li>element 3</li> | |
</ul></li> | |
<li>Tea <ul> | |
<li>element 2</li> | |
<li>element 3</li> | |
</ul></li> | |
<li>Milk <ul> | |
<li>element 2</li> | |
<li>element 3</li> | |
</ul></li> | |
</ul> | |
<p id="demo">Click the button to remove the first item from the list</p> | |
<button onclick="myFunction()">Try it</button> | |
<script> | |
function myFunction() | |
{ | |
var list=document.getElementById("myList"); | |
list.removeChild(list.childNodes[0]); | |
list.removeChild(list.childNodes[0]); | |
} | |
</script> | |
</body> | |
</html> | |
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.common.exceptions import NoSuchElementException | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.by import By | |
import time | |
browser = webdriver.Firefox() # Get local session of firefox | |
browser.get("http://localhost:8000/test.html") # Load page | |
el = browser.find_element('css selector', '#myList>li') | |
print el.text | |
browser.find_element('css selector', 'html>body>button').click() | |
print el.text | |
browser.close() |
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
(sel)bebe@P5171:~/test$ python test.py | |
Coffee | |
element 2 | |
element 3 | |
Traceback (most recent call last): | |
File "test.py", line 13, in <module> | |
print el.text | |
File "/home/bebe/.virtualenvs/sel/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 50, in text | |
return self._execute(Command.GET_ELEMENT_TEXT)['value'] | |
File "/home/bebe/.virtualenvs/sel/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 228, in _execute | |
return self._parent.execute(command, params) | |
File "/home/bebe/.virtualenvs/sel/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute | |
self.error_handler.check_response(response) | |
File "/home/bebe/.virtualenvs/sel/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 152, in check_response | |
raise exception_class(message, screen, stacktrace) | |
selenium.common.exceptions.StaleElementReferenceException: Message: u'Element is no longer attached to the DOM' ; Stacktrace: Method fxdriver.cache.getElementAt threw an error in resource://fxdriver/modules/web_element_cache.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment