【问题标题】:How to sendKeys in textBox? for automation如何在文本框中发送密钥?用于自动化
【发布时间】:2018-04-18 09:40:01
【问题描述】:

我正在为这个站点http://onliner.by 使用 selenium 对 c# 进行测试。 一开始我必须在这个网站上获得授权。

我在右上角找到(通过xpath)名称为“Вход”的按钮并单击它。

然后刷新并更改页面,但链接保持不变(http://onliner.by)。

我需要在这个页面上输入登录名和密码并提交。但我做不到。 我创建了这些元素的 Xpath 路径并使用了以下代码:

//this doesn't work
driver.FindElement(By.XPath("//*[@id='auth-container__forms']/div/div[2]/form/div[1]/div[1]/input")).SendKeys("user");
driver.FindElement(By.XPath("//*[@id='auth-container__forms']/div/div[2]/form/div[1]/div[2]/input")).SendKeys("password");
driver.FindElement(By.XPath("//*[@id='auth-container__forms']/div/div[2]/form/div[3]/div/button")).Click();

我该怎么做?我尝试使用 SwitchTo().Frame 但也没有用。

我将非常感谢您的帮助。

【问题讨论】:

  • 正确安排问题
  • 用户名和密码不在frame里,所以不用切换到frame里。我检查了你的 xpath 是否正确。可能的原因是您需要等待登录页面加载完成才能对其进行任何操作。点击右上角的“Вход”后尝试添加睡眠。
  • 是的,非常感谢)但是 SwitchTo().frame 不需要。 WebDriverWait 解决了这个问题)

标签: selenium xpath selenium-webdriver ui-automation browser-automation


【解决方案1】:

你必须像这样等待元素的可用性

new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((Locator Value)));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-01
    • 2012-10-22
    • 1970-01-01
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    相关资源
    最近更新 更多