This is my code
from selenium import webdriver
class Testone(unittest.TestCase):
def setUp(self):
self.driver = webdriver.PhantomJS()
self.driver.cookiesEnabled = 'True'
self.driver.set_window_size(1366,768)
def test_url(self):
max_wait = 10
self.driver.get("http://ads.ibibo.com/afr.php?z=50005")
self.driver.set_page_load_timeout(max_wait)
self.assertIn("Advertisement", self.driver.title)
self.driver.find_element_by_xpath("//img").click()
#self.driver.find_element_by_css_selector("img").click()
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
I am getting this screen
Warning (from warnings module): File "C:\Python34\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 76 while not utils.is_connectable(self.port): ResourceWarning: unclosed E ====================================================================== ERROR: test_url (__main__.Testone) ---------------------------------------------------------------------- Traceback (most recent call last): File "C:\Users\siddharth.jain\Documents\Automation\test.py", line 28, in test_url self.driver.find_element_by_xpath("//div[@id='']/a/img").click() File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 230, in find_element_by_xpath return self.find_element(by=By.XPATH, value=xpath) File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 662, in find_element {'using': by, 'value': value})['value'] File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 173, in execute self.error_handler.check_response(response) File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 166, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: {"errorMessage":"Unable to find element with xpath '//div[@id='']/a/img'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"103","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:57252","User-Agent":"Python-urllib/3.4"},"httpVersion":"1.1","method":"POST","post":"{\"value\": \"//div[@id='']/a/img\", \"using\": \"xpath\", \"sessionId\": \"da0e56b0-8996-11e4-96ef-e721b9f30c36\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/da0e56b0-8996-11e4-96ef-e721b9f30c36/element"}} Screenshot: available via screen ---------------------------------------------------------------------- Ran 1 test in 3.075s FAILED (errors=1)