There's no isTextPresent
in Selenium 2 (WebDriver)
What is the correct way to assert the existence of some text on a page with WebDriver?
Object OrientedSelenium WebDriver is purely object oriented API, whereas Selenium RC is less object oriented API. WebDriver is entirely based on object oriented programming languages like Java, C#, etc.
Selenium 2. Selenium 1 = Selenium Remote Control. Selenium 2 = Selenium 1 + WebDriver. Depends on the core libraries which could run on any browser which would support JavaScript. It runs JavaScript natively and test cases created can be run on different browsers.
The primary new feature of Selenium 2 is the integration of WebDriver, a rival web application testing framework to Selenium 1 (a.k.a. Selenium RC). While Selenium RC runs a JavaScript application within the browser, WebDriver controls the browser directly using native browser support or browser extensions.
Selenium RC comprises an additional layer of JavaScript known as the core which makes it slower. Selenium RC has complicated and redundant APIs. Selenium RC is not compatible with the HTMLUnit browser (required for headless execution). Selenium RC has in-built HTML report generation features for test results.
I normally do something along the lines of:
assertEquals(driver.getPageSource().contains("sometext"), true);
assertTrue(driver.getPageSource().contains("sometext"));
Page source contains HTML tags which might break your search text and result in false negatives. I found this solution works much like Selenium RC's isTextPresent API.
WebDriver driver = new FirefoxDriver(); //or some other driver
driver.findElement(By.tagName("body")).getText().contains("Some text to search")
doing getText and then contains does have a performance trade-off. You might want to narrow down search tree by using a more specific WebElement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With