即使使用selenium Web驱动程序在移动Web应用程序中成功执行了click()方法,屏幕也无法导航 [英] The screen is not navigating even the click() method is executed successfully in mobile web app using selenium web driver

查看:115
本文介绍了即使使用selenium Web驱动程序在移动Web应用程序中成功执行了click()方法,屏幕也无法导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Selenium Web驱动程序单击移动Web应用程序上的按钮.该按钮位于,可以导出按钮上的文本,甚至单击事件也能很好地执行.但是导航不会发生.

I was trying to click a button on my mobile web app, using selenium web driver. The button is located, the text over the button can be derived and even the click event is performing well. But the navigation doesn't occur.

我尝试使用Click()方法,sendKeys()方法以及脚本执行器.但是无法进一步处理.

I tried with Click() method, sendKeys() method and also with script executor. But couldn't process further on.

代码:

public class TestWeb
{  

    WebDriver driver; 

    private Selenium selenium;   

    @Before
    public void setUp() throws Exception {
      driver = new IPhoneDriver();
      driver.get("http://10.5.95.25/mobilebanking");       
    }

    @Test
    public void TC() throws Exception  { 
        System.out.println("page 1");
        Thread.sleep(5000);
        WebElement editbtn1 = driver.findElement(By.id("ext-comp-1018"));
        String s1 = editbtn1.getText();
        System.out.println(s1);
        editbtn1.click();
        editbtn1.sendKeys(Keys.ENTER);
        ((JavascriptExecutor)driver).executeScript("arguments[0].click;", editbtn1); 

        System.out.println("ok");
    }

@After
    public void tearDown() throws Exception {
         System.out.println("*******Execution Over***********");
    }
}

我分别尝试了click,sendKeys和ScriptExecutor,也进行了组合.它正在执行,没有任何错误,但是导航没有发生.

I tried click, sendKeys and ScriptExecutor separately and also combined. It is executing without any error but the navigation doesn't occur.

有人可以通过其他方法在按钮上执行点击功能吗?

Does anybody can help me with some other ways to perform click function on the button?

Ram

推荐答案

这可能不是您的问题,但我注意到"ext-comp-",并猜测您正在使用extjs.

This may not be your issue but I noticed "ext-comp-" and guess you are using extjs.

我使用的是GXT,虽然按ID进行查找可以解决很多问题,但是在某些提交按钮上却没有.

I'm using GXT and while finding by id worked for many things, on some submit buttons it didn't.

我不得不在firefox中使用firebug来定位元素并复制xpath. 然后我可以通过

I had to use firebug in firefox to locate the element and copy the xpath. Then I could click the element by

driver.findElement(By.xpath("//div[@id='LOGIN_SUBMIT']/div/table/tbody/tr[2]/td[2]/div/div/table/tbody/tr/td/div")).click();  // worked

这也让我无声无息地失败了.我的提交按钮的ID为LOGIN_SUBMIT,所以我不知道为什么以下操作失败,但是....

It was failing silently for me too. My submit button has the id of LOGIN_SUBMIT so I don't know why the following failed but ....

driver.findElement(By.id("LOGIN_SUBMIT")).click();//failed  

以下是一个确切的示例(案例2之1):

WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='gwt-debug-LOGIN_SUBMIT']")));
    //wait.until(ExpectedConditions.elementToBeClickable((By.id("gwt-debug-LOGIN_SUBMIT"))));  <!-- id works as well

确定,因此找到了元素.它将超时并抛出异常.

OK so the element is found. It will timeout and throw an exception if it is not.

仍然,以下操作失败(在Firefox中,适用于chrome),没有错误,并且页面无法导航.

Still, the following fails (under firefox, works with chrome) with no error and the page does not navigate.

driver.findElement(By.xpath("//div[@id='gwt-debug-LOGIN_SUBMIT']")).click();
//driver.findElement(By.id("gwt-debug-LOGIN_SUBMIT")).click(); <-- fails too 

我要做的是:

driver.findElement(By.xpath("//div[@id='gwt-debug-LOGIN_SUBMIT']/div/table/tbody/tr[2]/td[2]/div/div/table/tbody/tr/td/div")).click();

所以我的经验是,即使我找到带有xpath的元素,除非我使用完整的xpath,否则单击都会失败.

So my experience was that even if I found the element with xpath, clicking failed unless I used a complete xpath.

这是另一个确切的示例(案例2之2):

我可以找到一个像这样的元素:

I can find an element like so:

WebElement we = driver.findElement(By.xpath("//*[@id=\"text" + i + "\"]"));

我知道我找到了它,因为我可以通过以下方式查看文字:

I know I have found it because I can see the text via:

 we.getText();

仍然按我发现的路径进行选择失败.

Still selecting by the path I found it fails.

//get outta town man the following fails
driver.findElement(By.xpath("//*[@id=\"text" + i + "\"]")).click();

在这种情况下,没有像情况1那样尝试更多的显式xpath 我要做的是使用CSS:

In this case there is not more explicit xpath to try as in case 1 What I had to do was use css:

//bingo baby works fine
driver.findElement(By.cssSelector("div#text" + i + ".myChoices")).click();

实际上,我通过萤火虫获得了CSS路径,而不是缩短了它.

Actually, I obtained the css path via firebug than shortened it.

//this is what I recieved
html.ext-strict body.ext-gecko div#x-auto-0.x-component div#x-auto-1.x-component div#x-auto-3..myBlank div#choicePanel1.myBlank div.x-box-inner div#text3.myChoices  //text3 is the id of the element I wanted to select

我不知道您是否能找到所需的xpath和CSS选择器,但我相信我确实经历了您所做的事情.

Whether or not you can figure out your needed xpaths and css selectors, I don't know, but I believe I experienced exactly what you did.

这篇关于即使使用selenium Web驱动程序在移动Web应用程序中成功执行了click()方法,屏幕也无法导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆