Selenium Firefox驱动程序中的WebElement的GetAttribute返回空 [英] GetAttribute of WebElement in Selenium Firefox Driver Returns Empty
问题描述
Selenium
ChromeDriver
就好了。我的任务是在 FirefoxDriver
上进行测试。 部分测试我们将文本输入到登录字段中,然后检查登录字段以确保输入。我们检查字段的方式是这样的
public virtual string Text => WebElement.GetAttribute( 值); $!
while(!Text.Equals >这在 Chrome
中工作得很好。但是它并不在 Firefox
中。当我调试测试时,它显示 Text
是
或空/空白。如果我打开Firefox,我可以执行 document.getElementById(login).value
,并返回正确的值。 FirefoxDriver
中的 WebElement.GetAttribute
的不同实现方式
>或者我只是错过了什么?解决方案 很难说你的情况为什么不工作 Firefox
,浏览器之间没有不同的实现。您可以使用 IJavascriptExecutor
替代解决方案,如下所示: -
$ b $ pre $ I $ aaScriptScriptExecutor js = driver作为IJavaScriptExecutor;
string Text =(string)js.ExecuteScript(return arguments [0] .value,WebElement);
So I have a test that was written, and the test runs and works using the Selenium
ChromeDriver
just fine. I was tasked with getting the tests working on the FirefoxDriver
as well.
Part of the test we input text into a login field, and then check the login field to make sure it was input. The way we check the field is like this
public virtual string Text => WebElement.GetAttribute("value");
while (!Text.Equals(inputText) && count++ < 3)
This works perfectly fine in Chrome
. However it does not in Firefox
. When I debug the test, it shows that Text
is ""
or empty/blank. If I open Firefox, I can do this document.getElementById("login").value
and it returns the correct value.
Is WebElement.GetAttribute
implemented differently in the FirefoxDriver
or am I just missing something?
解决方案 It's hard to say in your case why is not working on Firefox
, there is no different implementation between browsers. You can try alternate solution using IJavascriptExecutor
instead as below :-
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string Text = (string)js.ExecuteScript("return arguments[0].value", WebElement);
这篇关于Selenium Firefox驱动程序中的WebElement的GetAttribute返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文