我正在尝试自动化一个reactjs应用程序和我们的项目正在使用的框架,该框架构建在C#和protractor-net之上。
在任何单击或断言函数之后,我得到以下错误,但代码中定义的操作成功执行。
System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> OpenQA.Selenium.WebDriverTimeoutException : timeout此错误的原因是什么?
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
using Protractor;
using System;
using System.Collections.Generic;
public Class personalinformations
{
private NgWebDriver _ngdriver;
public PersonalInformations(IWebDriver driver)
{
_ngdriver = new NgWebDriver(driver);
PageFactory.InitElements(_ngdriver, this);
_ngdriver.IgnoreSynchronization = true;
}
[FindsBy(How = How.Id, Using = "btnSubmit")]
private IWebElement btnsave { get; set; }
public void saveSection()
{
WebDriverWait wait = new WebDriverWait(ngdriver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*@id='btnSubmit']"));
btnsave.Click();
}
}注意:在使用Thread.Sleep(1000)进行等待时,有时代码works.Also与我尝试使用Javascript单击元素时的结果是相同的。
发布于 2018-04-30 22:12:54
一旦您通过WebDriverWait和ExpectedConditions方法ElementIsVisible等待元素,如下一步所示,您将调用Click(),因此您需要按如下方式调用ElementToBeClickable方法,而不是ElementIsVisible方法:
public void saveSection()
{
WebDriverWait wait = new WebDriverWait(ngdriver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*@id='btnSubmit']"));
btnsave.Click();
}发布于 2021-11-02 07:33:50
这是一个有趣的异常:"System.Reflection.TargetInvocationException : Exception已被调用的目标抛出。“;我遇到这个问题好几次了,但我搜索了这篇文章"Exception has been thrown by the target of an invocation" error (mscorlib)他们说你应该检查这个异常背后的根本原因。所以我添加了一个
尝试{element.Click();}捕获(异常e){Console.WriteLine(e);}
然后异常似乎逃脱了.
https://stackoverflow.com/questions/50090018
复制相似问题