这是我的密码
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()
我要得到这个屏幕
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)
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
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)
element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//img"))
)
element.click()
def tearDown(self):
self.driver.quit()
if __name__ == '__main__':
unittest.main()
我面临的错误截图 上面的一行显示了错误,它表示。我在堆栈溢出上看到过这种问题,但解决方案对我没有帮助
问题内容: 我有以下XPath: 当我在XPath Checker(Firefox扩展)中试用此XPath时,它一直都能完美运行。但是当我在Selenium中执行以下操作时: 它不断给我以下日志错误: 我为解决这个问题而疯狂。有人看到我的代码行有任何错误吗? 问题答案: 该查询字符串不应该像这样(根据javadoc api)吗?
有我试图点击按钮代码。 我添加带有图片的Web元素代码。我怎么能用Java按下这个按钮。我这样试过; 线程睡眠(1000);driver.findElement(按类名(“_abm0”)).单击();OR 线程睡眠(1000);driver.findElement(按类名(“._abl-._abm2”)).单击();OR 线程睡眠(1000);driver.findElement(按类名(“_ab
我正在为我的公司自动化IdentiGO应用程序,并得到以下错误: 下面是我的代码,由于与我的问题无关,所以省略了导致该页面的脚本。 在此代码之前的页面上,用户选择约会日期和时间;我希望脚本等待“开始”按钮被推,然后在下面的截图中点击“继续”: null https://jsfiddle.net/khf4tym3/ 当我单击“View page source”时,弹出的html不会显示在源代码中,所
我正在尝试使用python selenium脚本单击gmail主页右上角的“登录”标签。我使用firebug/firepath为这个类找到了正确的xpath,在使用浏览器工具时,它似乎工作得很好,但当脚本尝试使用xpath查找相同的元素时,它失败了。如果你能给我指出正确的方向,我将不胜感激。非常感谢。 Url:https://www.google.com/gmail/about/ 附言:我对硒比较
Selenium.Common.Exceptions.NosuChelementException:消息:没有这样的元素:找不到元素: