我的方案:登录我的帐户后,将在网页上打开插页式广告。我的用例是,如果显示插页式广告,我会关闭插页式广告
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:消息:无法找到元素:{&#34;方法&#34;:&#34; xpath&#34;,&#34;选择器&#34;:&#34; / HTML /体/格[1] / DIV [2] / DIV /地图/区域[1]&#34;} 堆栈跟踪: 在FirefoxDriver.prototype.findElementInternal_(file:///var/folders/7f/q00y41s11xdfknssfymz3qfc0000gv/T/tmp8w0k6J/extensions/fxdriver@googlecode.com/components/driver-component.js:10770) at fxdriver.Timer.prototype.setTimeout /&lt; .notify(file:///var/folders/7f/q00y41s11xdfknssfymz3qfc0000gv/T/tmp8w0k6J/extensions/fxdriver@googlecode.com/components/driver-component.js:625)< / p>
答案 0 :(得分:1)
首先来看看:waits methods
我建议你尝试这个解决方案:
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((inter1, "myDynamicElement"))
)
finally:
driver.quit()
希望这对你有用。
答案 1 :(得分: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