【问题标题】:C# selenium cant find input in formC# selenium 在表单中找不到输入
【发布时间】:2016-05-12 17:47:58
【问题描述】:

我正在尝试在表单中找到一个按钮...但它没有找到它... 我尝试过使用 threading.sleep(5000);但它没有帮助。 我尝试了很多方法,但没有任何帮助它总是说它无法找到按钮...... 这是我的代码:

IWebElement startb2 = driver.FindElement(By.XPath("//form/*[@name='start']"));

这是表单的html代码:

<form method="post" action="php/PickFruits.php">
<input type="submit" name="start" value="התחל לקטוף" class="button_submit" style="margin-right:-97px;">
</form>

我不想使用该值,因为它是希伯来语...我不能在 c# 控制台中使用它...请帮帮我。

编辑:

现在它找到了输入的位置,但它没有点击它...代码:

IWebElement startb = driver.FindElement(By.XPath("//*[@type='submit']"));
startb.Click();

【问题讨论】:

  • 试试 xpath = '//*[@type="submit"]'
  • 它工作但它没有点击它:l 代码:IWebElement startb = driver.FindElement(By.XPath("//*[@type='submit']")); startb.Click();
  • 点击时是否出现错误?
  • 在执行点击操作之前尝试添加一些延迟。
  • 我添加了但仍然没有:l

标签: c# html forms selenium


【解决方案1】:

要切换到 iframe,请使用以下代码。

//To find the iframe
IWebElement Object = driver.FindElement(By.XPath("//*[@class='active_iframe']");
//To switch to and set focus to the iframe
driver.SwitchTo().Frame(Object);

然后进行点击操作。

IWebElement startb = driver.FindElement(By.XPath("//*[@type='submit']"));
startb.Click();

【讨论】:

  • 我的 iframe 的 xpath 是什么?我不知道:l iframe 代码:
  • 根据您发布的内容添加了 XPATH。立即查看
  • 但是等我用完这个 iframe 我怎么回来?我的意思是我如何停止关注该 iframe 并开始查看所有网站?
  • driver.SwitchTo().DefaultContent();您可以使用它返回页面上最顶部的框架
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-11
  • 2022-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多