webdriver (c#) - 循环页面刷新直到元素样式不存在
webdriver (c#) - looping page refresh until an elements style doesn't exist
我正在努力寻找我需要的方法。这是我想要做的:
- 我要加载网页
- 在该网页上,我想等到特定元素及其样式属性包含 "hidden: true;"。当这个样式出现时,页面已经完全加载,所以我可以继续我的测试
- 我需要继续刷新网页,直到上述条件成立 - 请假设我需要继续刷新。我知道这看起来很愚蠢。
这是我正在尝试的
第 1 步:
导航到网页(凭记忆编写代码):
driver.Navigate().GoToUrl("http://example.com");
第 2 步:
从特定元素中查找样式(凭记忆编写代码)
Iwebelement MyElement = driver.findElement(By.id("example"));
Iwebelement MyElementStyle = MyElement.GetAttribute("style");
第 3 步:
如果元素在页面加载时具有 "hidden: true;" 样式,则不执行任何其他操作执行页面刷新,直到元素不包含 "hidden: true;" 样式(从内存中编写代码)
if(MyElementStyle.Contains("hidden: true;"))
{
// do nothing
}
else
{
driver.Navigate().GoToUrl("http://example.com");
}
这似乎有效,但上面的代码只会刷新页面一次,所以我需要循环而不是使用 if 语句。
谁能提供一些建议或建议更好的方法来解决这个问题?
I am not sure what language binding you are using but looks like a mixture of C# and java and if that's the real test code it will not work.
使用do while
循环进行post检查并检查属性是否具有预期值。
IWebElement MyElement = Driver.FindElement(By.Id("example"));
string MyElementStyle = MyElement.GetAttribute("style");
do
{
Driver.Navigate().Refresh();
} while (MyElementStyle.Contains("hidden: true;"));
我正在努力寻找我需要的方法。这是我想要做的:
- 我要加载网页
- 在该网页上,我想等到特定元素及其样式属性包含 "hidden: true;"。当这个样式出现时,页面已经完全加载,所以我可以继续我的测试
- 我需要继续刷新网页,直到上述条件成立 - 请假设我需要继续刷新。我知道这看起来很愚蠢。
这是我正在尝试的
第 1 步:
导航到网页(凭记忆编写代码):
driver.Navigate().GoToUrl("http://example.com");
第 2 步:
从特定元素中查找样式(凭记忆编写代码)
Iwebelement MyElement = driver.findElement(By.id("example"));
Iwebelement MyElementStyle = MyElement.GetAttribute("style");
第 3 步:
如果元素在页面加载时具有 "hidden: true;" 样式,则不执行任何其他操作执行页面刷新,直到元素不包含 "hidden: true;" 样式(从内存中编写代码)
if(MyElementStyle.Contains("hidden: true;"))
{
// do nothing
}
else
{
driver.Navigate().GoToUrl("http://example.com");
}
这似乎有效,但上面的代码只会刷新页面一次,所以我需要循环而不是使用 if 语句。
谁能提供一些建议或建议更好的方法来解决这个问题?
I am not sure what language binding you are using but looks like a mixture of C# and java and if that's the real test code it will not work.
使用do while
循环进行post检查并检查属性是否具有预期值。
IWebElement MyElement = Driver.FindElement(By.Id("example"));
string MyElementStyle = MyElement.GetAttribute("style");
do
{
Driver.Navigate().Refresh();
} while (MyElementStyle.Contains("hidden: true;"));