2016-05-16 6 views
-2

私のシナリオ:アカウントにログインすると、ウェブページ上にインタースティシャルが開きます。私のユースケースは、間質が表示されている場合、私はpythonセレンの要素の可視性をどのように見つけることができますか?

inter=driver.find_element_by_xpath("/*x-path location/*") 

if inter1.is_displayed(): 
    inter1.click() 

などの間質を閉じます。しかし、間質は表示されません少数のユーザーのために、私は以下の

if(driver.find_element_by_xpath("/*x-path location/*").is_displayed()): 
    driver.find_element_by_xpath("/*x-path location/*").close() 

else: 
    (kept my rest of the class part here) 

しかし、私のように私のコードを更新しましたですこのスクリプトは、事前に以下のエラーで

いくつかのいずれかの提案を手伝ってくれるおかげで、失敗した

selenium.common.exceptions.NoSuchElementException:メッセージ:要素を見つけることができません:{"method": "xpath"、 "selector": "/ html/body/div [1]/div [2]/div/map/area [ 1]」} Stacktrace:FirefoxDriver.prototype.findElementInternal_(file:///var/folders/7f/q00y41s11xdfknssfymz3qfc0000gv/T/tmp8w0k6J/extensions/[email protected]/components/driver-component.js:10770)の at fxdriver.Timer.prototype.setTimeout/< .notify(ファイル:///var/folders/7f/q00y41s11xdfknssfymz3qfc0000gv/T/tmp8w0k6J/extensions/[email protected]/components/driver-component.js:625)

すべての

答えて

1

初に見てみましょう:waits methods

私はあなたがこのソリューションを試してくださいすることを示唆している:あなたのために動作します

try: 
    element = WebDriverWait(driver, 10).until(
     EC.presence_of_element_located((inter1, "myDynamicElement")) 
    ) 
finally: 
    driver.quit() 

希望。

0

上記のユースケースのためのソリューションを探す:

def is_text_present(driver): 

try : 
    print "This is is_text_present method" 
    body = driver.find_element_by_xpath("Your xpath") 
    body.click(); 
except NoSuchElementException, e: 
    return False 
return True 
関連する問題