-->

该屏幕不连导航点击()在移动Web应用程序中使用硒网络驱动程序成功执行的方法(The screen

2019-10-16 22:34发布

我试图点击我的移动网络应用程序的按钮,使用硒网络驱动程序。 该按钮位于,可以得出在按钮上的文本,甚至click事件表现良好。 但导航不会发生。

我试着用点击()方法的SendKeys()方法,并与脚本执行。 但未能进一步上处理。

码:

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***********");
    }
}

我尝试点击,和的SendKeys分别ScriptExecutor也相结合。 这是一个没有任何错误执行,但导航不会发生。

是否有人可以帮助我做一些其他的方式来对按钮进行点击的功能?


内存

Answer 1:

这可能不是你的问题,但我注意到,“EXT-补偿 - ”猜你正在使用ExtJS的。

我使用GXT只要通过ID找到工作了很多东西,在某些提交它没有按键。

我不得不使用Firefox中的Firebug定位元素和复制的XPath。 然后,我可以单击该元素通过

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

它静静地失败对我来说太。 我的提交按钮有LOGIN_SUBMIT的ID,所以我不知道为什么失败后,但....

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

确定这样的元素被发现。 它会超时,并抛出一个异常,如果事实并非如此。

不过,下面的失败(火狐下,镀铬工作),没有错误,页面没有导航。

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。

下面是另一个例子确切(箱子2 2):

我能找到像这样的元素:

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

我知道,我已经找到了它,因为我可以通过看到的文字:

 we.getText();

通过我发现它失败的路径仍然选择。

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

在这种情况下,有没有更明确的XPath尝试为1的情况下我该怎么办是使用CSS:

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

其实,我获得通过萤火虫的CSS路径比缩短它。

//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选择,我不知道,但我相信我有经验,你做了什么。



文章来源: The screen is not navigating even the click() method is executed successfully in mobile web app using selenium web driver