2016-06-22 8 views
0

私は1年以上同じスクリプトを使用していますが、昨日から画像を持つリンクをクリックするとこのエラーが発生しています。私はxpathで要素を取得して、それをクリックしています。セレンのpythonで "要素がクリックできません"エラー

test_101_HomePage_links (__main__.SprintTests) ... ERROR 

====================================================================== 
ERROR: test_101_HomePage_links (__main__.SprintTests) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "D:\Zaakpay\website\sanity results\debug\tests.py", line 17, in test_101_HomePage_links 
    a.click() 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 73, in click 
    self._execute(Command.CLICK_ELEMENT) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 456, in _execute 
    return self._parent.execute(command, params) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute 
    self.error_handler.check_response(response) 
    File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response 
    raise exception_class(message, screen, stacktrace) 
WebDriverException: Message: Element is not clickable at point (281.25, 61). Other element would receive the click: <span></span> 


---------------------------------------------------------------------- 
Ran 1 test in 23.062s 

FAILED (errors=1) 

その他の情報: のfirefox、 同じスクリプトを使用して は昨日まで

私のコード罰金働いていた、のpythonを使用して、Windows、 を使用して:私はクリックしようとしています

import unittest 
from selenium import webdriver 
import datetime 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile 
import time 

class SprintTests(unittest.TestCase): 

    def setUp(self): 
     self.driver = webdriver.Firefox() 
     self.driver.implicitly_wait(30) 
     self.driver.maximize_window() 
     self.driver.get("https://www.zaakpay.com") 

    def test_101_HomePage_links(self): 
     a= self.driver.find_element_by_xpath("/html/body/div[5]/div[1]/div[3]/ul/li[1]/a/i") 
     a.click() 
     time.sleep(5) 
     a = self.driver.find_element_by_xpath('//*[@id="view1"]/p') 
     b=a.text 
     self.assertEqual('-Payment Gateway Services.\n-More than you want payment options with.\n-major credit cards, debit cards and 52 netbanking banks.\n-Fastest Merchant Approval.\n-Smooth integration across 22 platforms.\n-Start in minutes.\n-Multi-Currency Processing Service with 13 currencies.\n\nSIGN UP',b) 


    def tearDown(self): 
     self.driver.quit() 

if __name__ == '__main__': 
    unittest.main(verbosity=2) 

リンクテキストの上に円形のイメージです - ウェブサイト支払いゲートウェイ

+0

は、ちょうどこの例外がスローされると、後のスクリーンショットを取ると、あなたの質問に含めます。何かがあなたのクリックをブロックしています –

+0

どの要素が代わりにこのクリックを持っていますか?教えてくれますか?前にこのエラーが発生しました。クリックしたかった要素がマスクされているか、見えなくなっている可能性があります。 –

+0

driver.save_screenshot(「保存するパス\\ screen.jpeg」) –

答えて

1

XPATHを使用するliこの/html/body/div[5]/div[1]/div[3]/ul/li[1]/a/iにはいくつかの理由で問題があります。

まず第一に、非常に脆いです。それが必要とするのは、夜間に視覚的に知覚されるかもしれないサイトへのマイナーアップデートです。ハードコーディングされたdivインデックスは壊れます。サイト開発者がdivを追加してフォントスタイルを少し変更した場合、XPATHが完全に壊れている可能性があります。

第2に、一度壊れてしまえば、デバッグが不可能になります。私は、あなたがクリックしようとしているものは全く考えていません。もしこれが誰かが修正しようとしていた生産コードであれば、あなたがクリックしようとしていたものはまったく分かりません。

私の最高の推測では、zaakpayはDOM内のターゲット要素の位置をわずかに変更した、少し小さく知覚できない変更を加えたということです。あなたは、私は以下やったよう//div[@class=\"prdtBlck\"]/ul/li/a、のようなものにXPATHを更新すると、あなたのスクリプトの動作:

import unittest 
from selenium import webdriver 
import datetime 
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile 
import time 

class SprintTests(unittest.TestCase): 

    def setUp(self): 
     self.driver = webdriver.Firefox() 
     self.driver.implicitly_wait(30) 
     self.driver.maximize_window() 
     self.driver.get("https://www.zaakpay.com") 

    def test_101_HomePage_links(self): 
     a=self.driver.find_element_by_xpath("//div[@class=\"prdtBlck\"]/ul/li/a") 
     a.click() 
     time.sleep(5) 
     a = self.driver.find_element_by_xpath('//*[@id="view1"]/p') 
     b=a.text 
     self.assertEqual('-Payment Gateway Services.\n-More than you want payment options with.\n-major credit cards, debit cards and 52 netbanking banks.\n-Fastest Merchant Approval.\n-Smooth integration across 22 platforms.\n-Start in minutes.\n-Multi-Currency Processing Service with 13 currencies.\n\nSIGN UP',b) 


    def tearDown(self): 
     self.driver.quit() 

if __name__ == '__main__': 
    unittest.main(verbosity=2) 
+1

私はあなたが述べたものすべてには同意しますが、代わりにCSSセレクタ「a href = '#view1']」を使用することをお勧めします。これは、OPが探している要素を、相対参照なしで正確に取得します。 – JeffC

+0

私は同意する、それはよりよい道である。 –

+0

xpathに変更はありません。自分のコードとウェブページのxpathをチェックすることができます。私は自分のコードにこのようなリンクが100個あり、すべてが突然エラーを出し始めました。すべてのxpathを再度書き直すのは難しい作業です。とにかく、それは唯一の選択肢のようです。 –

関連する問題