2016-08-10 8 views
-1

ボタンをクリックする前にランダムなように見えるポップアップ問題を扱っています。要素が表示されているかどうかを確認する方法があるかどうかを知りたい場合は、要素が表示されていない場合は、スクリプトを実行し続けます。私の現在のスクリプトはエラーを取得し続けます。ポップアップが表示されたら、私のスクリプトはPERFECTを実行します。実際要素が見つからない場合、Python Seleniumスクリプトを実行し続ける

enter image description here

 self.driver.get(redirecturl) 
     self.driver.implicitly_wait(180) 
     login_frame = self.driver.find_element_by_name('injectedUl') 
     # switch to frame to access inputs 
     self.driver.switch_to.frame(login_frame) 
     # we now have access to the inputs 
     email = self.driver.find_element_by_id('email') 
     password = self.driver.find_element_by_id('password') 
     button = self.driver.find_element_by_id('btnLogin') 



     # input your email and password below 
     email.send_keys('') 
     password.send_keys('') 
     button.click() 
     ############# 

     onetouch = self.driver.find_element_by_xpath(".//*[@id='memberReview']/div[2]/div/div/div[2]/div[1]/div[1]/a") 
     if onetouch.is_displayed(): 
      time.sleep(2) 
      onetouch.click() 
     else: 
      print "onetouch not present....continuing script" 
     button2 = self.driver.find_element_by_id('confirmButtonTop') 
     button2.click() 
     button3 = self.driver.find_element_by_name('dwfrm_payment_paypal') 
     # if you want to test the program without placing an order, delete the button3.click() below this......... 
     button3.click 

答えて

0

find_element_by_xpath常にどちらかの要素を返すか、例外をスローし、そうそこにある場合:私のエラーは、私のエラーの絵です。ここ

onetouch = self.driver.find_element _by_xpath(""). 

で私のスクリプトで行われます指定されたロケータによって要素を実行することはできませんis_displayed()代わりにfind_elements_by_xpathを使用しようとすると、以下のように長さをチェックする必要があります: -

onetouch = self.driver.find_elements_by_xpath(".//*[@id='memberReview']/div[2]/div/div/div[2]/div[1]/div[1]/a") 

    if len(onetouch) > 0: 
     time.sleep(2) 
     onetouch[0].click() 
    else: 
     print "onetouch not present....continuing script" 
     ------- 
+0

ので、ちょうど私のスクリプトに自分の編集を追加する?? –

+0

@Tonysanchez、はい、あなたはこの変更であなたのスクリプトを編集する必要があります:... –

+0

今はどうなっているか知っていますよ!ありがとう –

0

次試してみてください。

from selenium.common.exceptions import NoSuchElementException 

try: 
    time.sleep(2) 
    self.driver.find_element_by_xpath(".//*[@id='memberReview']/div[2]/div/div/div[2]/div[1]/div[1]/a").click() 
except NoSuchElementException: 
    print "onetouch not present....continuing script" 
+0

はちょうど試しました。 didnt仕事。 –

+0

ターゲットページに 'HTML'を共有できますか?明らかに、提供された 'XPath' – Andersson

+0

の要素にない問題は、私のpaypalにログインした後、自動チェックアウトでこれを使用すると、時折ポップアップが出てきます。 –

関連する問題