Selenium webdriver 自动化安讯士银行网站

Selenium webdriver 自动化安讯士银行网站,selenium-webdriver,testng,Selenium Webdriver,Testng,您好,我想使用以下顺序和代码选择储蓄帐户。每次都会传递脚本,但根本没有单击保存帐户。 1.打开axis银行网站。2.打开产品下拉列表3。在it 4中打开帐户部分。点击储蓄账户5。打开下一页的“往来账户”部分 driver.get("http://www.axisbank.com/"); Actions action=new Actions(driver); WebElement prod=driver.findElement(By.id("product")); WebElement savin

您好,我想使用以下顺序和代码选择储蓄帐户。每次都会传递脚本,但根本没有单击保存帐户。 1.打开axis银行网站。2.打开产品下拉列表3。在it 4中打开帐户部分。点击储蓄账户5。打开下一页的“往来账户”部分

driver.get("http://www.axisbank.com/");
Actions action=new Actions(driver);
WebElement prod=driver.findElement(By.id("product"));
WebElement saving=driver.findElement(By.xpath("html/body/form/div[5]/div[1]/div[3]/div/div[1]/div[2]/div/div/ul[2]/ul/li[1]/a"));
WebElement account=driver.findElement(By.xpath("html/body/form/div[5]/div[1]/div[3]/div/div[1]/div[2]/div/div/ul[1]/li[1]/a"));
action.moveToElement(prod).moveToElement(account).moveToElement(saving).click();
Action composite=action.build();
composite.perform();
这对我很有用:

    Actions action=new Actions(driver);
//This is just to wait for that mobile window to go..You can add some other logic for that to disappear
            Thread.sleep(15000);
            WebDriverWait wait=new WebDriverWait(driver, 15,3000);
            WebElement prod=wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//span[text()='Products']")));
            WebElement saving=driver.findElement(By.xpath(".//a[starts-with(@title,'Savings Accounts')]"));
            WebElement account=driver.findElement(By.xpath(".//a[text()='Accounts']"));
            action.click(prod).perform();
            action.moveToElement(account).perform();
            action.moveToElement(saving).click().perform();

您忘记在
单击()上调用
perform()

您也可以尝试单击WebElement

action.moveToElement(prod).moveToElement(account).moveToElement(saving).perform();
saving.click();

它对你有用吗?它对我不起作用,行为是否也依赖于浏览器?我正在使用Chrome v51。@SahilSehgal这是我通常使用的方式。您也可以尝试在
moveToElement
之后单击“常规”(参见编辑后的答案)。@SahilSehgal是的,有时候Selenium与新浏览器的交互不好。您可以尝试降级浏览器,但这不一定是问题所在。谢谢,我认为这是浏览器兼容性问题,因为相同的脚本在我的朋友机器上工作。它对您有效吗?它对我不起作用,行为是否也依赖于浏览器?我使用的是Chrome v51。你能先试试Firefox吗?谢谢,我认为这是浏览器兼容性问题,因为我的朋友机器上使用的是同一个脚本。你能告诉我你使用的是哪个浏览器、版本和selenium java版本吗?我可以试着找到合适的梳子。对于sameI,我使用Chrome v51。我在firefox的朋友lappy上试用了这段代码,效果很好。谢谢你的关心。。
action.moveToElement(prod).moveToElement(account).moveToElement(saving).perform();
saving.click();