无法使用selenium webdriver单击下拉菜单中的链接

时间:2014-04-17 11:51:29

标签: java selenium-webdriver

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class HDFCBank {

public static void main(String[] args) {

     WebDriver driver=new FirefoxDriver();
     driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
     driver.get("http://www.hdfcbank.com/");
     Actions action=new Actions(driver);
     WebElement productsLink=driver.findElement(By.xpath("//span[text()='Products']"));
     action.moveToElement(productsLink).perform();
     try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
     WebElement cardLink=driver.findElement(By.xpath("//span[text()='Cards']"));
     action.moveToElement(cardLink).perform();
     try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
     WebElement creditcardLink=driver.findElement(By.xpath("//a[contains(text(),'Credit Cards')]"));
     action.moveToElement(creditcardLink).perform();
     try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
     //action.click(creditcardLink).perform();
     creditcardLink.click();

     WebElement customerLink=driver.findElement(By.xpath("//span[text()='Apply now']"));
     action.moveToElement(customerLink).perform();

     WebElement propertyLink=driver.findElement(By.xpath("//div[@class='lhssection']//a[text()='Loan Against Property']"));
     action.moveToElement(propertyLink).perform();
     action.click(propertyLink).perform();
  }
 }

a)鼠标指针移动到Products-> Cards->标题的信用卡,但它没有点击信用卡链接,即使我已经把这些声明,任何人都可以告诉我如何点击信用卡链接。

b)鼠标移动到标题的“立即应用”但未能移动Loan Against Property(根据代码)给出MoveTargetOutOfBoundsException,为什么会导致此异常,如何解决此问题?

0 个答案:

没有答案