尝试将IWebElement转换为By元素 [英] Trying to convert IWebElement into a By element
问题描述
让我们说我有一个页面对象
[FindsBy(How = How.Id, Using = "buttonSignIn")]
public IWebElement BtnSignin { get; set; }
我正试图将其传递给此方法,以将IWebElement
转换为By
元素.
public void MoveAndClick(IWebElement element)
{
var findElement = driver.FindElement((By)element);
Actions act = new Actions(driver);
act.MoveToElement(findElement);
act.Click(findElement);
act.Perform();
}
我知道这段代码可以在不将该元素转换为By
元素的情况下工作,但是为了使我的测试正常工作,我需要弄清楚如何将IWebElement
转换为By
元素.>
运行此命令时,我得到一个空异常错误.有人对此有一个简单的解决方案吗?
简短的回答,这是不可能的. Selenium的开发人员已决定对此没有有用的用例.
Lets say I have a page object
[FindsBy(How = How.Id, Using = "buttonSignIn")]
public IWebElement BtnSignin { get; set; }
I am trying to pass that into this method to convert the IWebElement
into a By
element.
public void MoveAndClick(IWebElement element)
{
var findElement = driver.FindElement((By)element);
Actions act = new Actions(driver);
act.MoveToElement(findElement);
act.Click(findElement);
act.Perform();
}
I know that this piece of code will work without casting the element into a By
element, however for my tests to work I need to figure out how to convert the IWebElement
into a By
element.
When I run this I get a null exception error. Does anyone have a simple solution for this?
Short answer, this is not possible. The developers of Selenium have decided that there are no useful use cases for this.
这篇关于尝试将IWebElement转换为By元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!