简体   繁体   English

Selenium WebDriver Extjs示例代码

[英]Selenium WebDriver Extjs sample code

In a short time I will begin automating a web site that has ext.net controls in it. 在短时间内,我将开始自动化其中具有ext.net控件的网站。 I actually tried to automate a simple scenario as a sample from " http://examples.ext.net/ " site. 实际上,我尝试将“ http://examples.ext.net/ ”站点中的示例作为一个简单的场景进行自动化。 Click > Form > Field Note > Overview but I couldn't manage to write text to simple note textbox. 单击>表单>字段注释>概述,但是我无法将文本写入简单注释文本框。 Could you provide a code sample that is working? 您能否提供一个有效的代码示例? I tried to get by XPath and other means that can be used with by class. 我试图通过XPath和其他可与类一起使用的方式来获得。 If I try to get all the inputs I get them but SendKeys or Click methods don't work. 如果我尝试获取所有输入,则可以获取,但是SendKeys或Click方法不起作用。 I get Element Not Visible exception. 我收到“元素不可见”异常。 Could you provide a code sample that is working? 您能否提供一个有效的代码示例?

    IWebElement htmlElement = driver.FindElement(By.TagName("html"));
    IList<IWebElement> inputList = htmlElement.FindElements(By.TagName("input"));

(I get all the inputs but I can't write note...) (我得到了所有输入,但是我不能写笔记...)

I did the following in Java and you can easily convert it to C# if you choose to. 我在Java中进行了以下操作,如果愿意,可以轻松地将其转换为C#。 I use a utility method to first properly query for the correct element: 我使用一种实用程序方法来首先正确查询正确的元素:

class Utils
{
      public WebElement query(String componentQuery) {

        String query =  componentQuery;
        String cmd = String.format("Ext.ComponentQuery.query('%s')[0]", query);
        String js = "return " + cmd + ".id;";
        String id = (String) ((JavascriptExecutor) driver).executeScript(js);
        return driver.findElement(By.id(id));
      }
 }

Then you can get your component here: 然后,您可以在此处获取组件:

WebElement componentElement=Utils.query("Your-ExtJS-Query-for-the-component-goes-here"+".inputEl");
componentElement.sendKeys(valuesToSet)    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM