2014-10-10 65 views
1

下面是这种情况:如何确定链接点击,或者不使用硒webriver

我想点击链接到自己的形象在网站上的图像,并确保该网站上没有图像链接到他们的形象(例如没有URL应该以JPG或PNG或GIF结尾)。为此,如果我们点击它,我可以点击并点击()事件失败。

这样的图像

HTML片段代码:

<a class="alignright" title="Project Management & Business Analysis"  
href="http://ambitechstrous.com/wordpress/project-management-business-analysis/"> 
<img class="entry-image attachment-post" width="150" height="150" itemprop="image" alt="project-  
management" src="http://ambitechstrous.com/wordpress/wp-content/uploads/2014/10/project- 
management-150x150.jpg"> 
</a> 

所以,可以在任何一个可以帮助我如何在硒的网络驱动程序来处理这样的场景

PS:另外,超链接,图片都无法点击,如果我们在网站上手动点击它们。这需要解决方法。

回答

2

我从你的问题知道你是想验证图像是否是可以点击的不是,如果我是正确的,那么我会建议使用下列内容:

/** 
* To verify whether image link is clickable or not 
* 
* @return true if image is clickable otherwise false 
*/ 
public boolean isImageLinkClickable(String xpath){ 
     WebElement imgElement = driver.findElement(By.xpath(xpath)); 
     try { 
      imgElement.click(); 
      return true; 
     } catch(Exception e){ 
      return false; 
     } 
} 
+0

感谢Priyanshu的帮助!是的。它工作并感谢您理解我的问题。做得好!! – 2014-10-10 06:37:40