【问题标题】:selenium AutoIt Keyboard Types Incorrectlyselenium AutoIt 键盘类型不正确
【发布时间】:2021-10-25 06:23:24
【问题描述】:

我在上传 Selenium 文件时使用 AutoIt

但是在上传的时候,输入的文件路径错误。

autoIt = new AutoItX3();

autoIt.WinActivate("Farklı Kaydet");
Thread.Sleep(1000);

autoIt.Send(AppDomain.CurrentDomain.BaseDirectory + @"video" + @"\" + textBox7.Text + "", 787000);
                autoIt.Send("{ENTER}");

如何让键盘输入更慢更流畅?

787000 我添加了,但它仍然运行得很快,并且正在寻找错误的文件路径。

如何用 c# 解决这个问题 提克托卡。我正在尝试上传视频

【问题讨论】:

    标签: c# selenium autoit-c#-wrapper


    【解决方案1】:

    首先,除非绝对必要,否则我不会使用 autoIt 进行文件上传。希望您可以通过页面上的输入元素来完成。如果您不确定如何操作,请参阅此处。 How to handle Windows file upload in .Net core using Selenium?

    至于您的问题,请单独输入字符。您还可以创建一个额外的 try/catch,这样如果键入的值不等于显示的值,您可以将其删除并再次执行。

            public static void TypeCharIndividually(IWebElement element, string expectedValue)
        {
            if (expectedValue == null)
            {
                return;
            }
            if (expectedValue == "n/a") { expectedValue = ""; }
            Driver.WaitForElementDisplayed(element);
            Driver.WaitForElementEnabled(element);
            element.Click();
            element.Clear();
            foreach (char c in expectedValue)
            {
                element.SendKeys(c.ToString());
                Thread.Sleep(500);
                Driver.WaitForSpinnerNoLongerDisplayed();
            }
            element.SendKeys(Keys.Tab);
            string receivedValue = element.GetAttribute("value");
            if (receivedValue != expectedValue)
            {
                throw new Exception("Typed element not as expected");
            }
    
        
    

    【讨论】:

      猜你喜欢
      • 2018-05-17
      • 1970-01-01
      • 2011-08-03
      • 2021-08-16
      • 1970-01-01
      • 2010-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多