如何使用selenium webdriver中的isTextPresent()等效函数来提高性能?

时间:2022-04-23 03:20:16

I have implemented data driven framework and so my isTextPresent function might have dynamic values. Also, I need to have a lot of assert texts in my application. I tried using xpath like

我已经实现了数据驱动框架,因此我的isTextPresent函数可能具有动态值。另外,我需要在我的应用程序中有很多断言文本。我尝试使用xpath之类的

boolean b=driver.findElement(By.xpath("//*[contains(.,stringc3)]")).getText().contains(stringc3);

where stringc3 is the text to be checked. But this implementation is taking a very long time(with webdriverbackedselenium, my tests used to take around 3 mins but with webdriver and above code, it takes around 20mins). So is there a way to make this test run faster?

其中stringc3是要检查的文本。但是这个实现需要很长时间(使用webdriverbackedselenium,我的测试过去需要大约3分钟但是使用webdriver和上面的代码,大约需要20分钟)。那么有没有办法让这个测试运行得更快?

I came to know that these functions are now supported for exports from selenium ide(http://code.google.com/p/selenium/source/detail?r=17718)

我开始知道这些函数现在支持从selenium ide导出(http://code.google.com/p/selenium/source/detail?r=17718)

So, is there any plan to implement isTextPresent function in webdriver?

那么,有没有计划在webdriver中实现isTextPresent函数?

1 个解决方案

#1


0  

I believe that isTextPresent is nothing but inner text from body tag. So you can grab all the text from the page first and then find the string you need.

我相信isTextPresent只不过是body标签的内部文本。因此,您可以先从页面中获取所有文本,然后找到所需的字符串。

string alltext = driver.findElement(By.tagName("body")).getText();

#1


0  

I believe that isTextPresent is nothing but inner text from body tag. So you can grab all the text from the page first and then find the string you need.

我相信isTextPresent只不过是body标签的内部文本。因此,您可以先从页面中获取所有文本,然后找到所需的字符串。

string alltext = driver.findElement(By.tagName("body")).getText();