getTitle() function returns incorrect result in Selenium web driver

Veeramani

I am trying to run a simple automated test script to get webpage title and verify it by using in selenium-webdriver by Java and IE, but getTitle() method returns strange result.

I could see when I run my test script initially is getting load a default page with below URL,

http://localhost:44585/

and then its navigating to my target URL (which is mentioned in script).

But still script is capturing the page title from above localhost URL not from target URL. Please advise how can I bypass the default (http://localhost:44585/) page.

Script

    public class start_with {
public static void main (String [] args)
{
    String url ="http://google.com";
    String title = "Google";
    String Actual_title;
    System.setProperty("webdriver.ie.driver", "C:\\..\\IEDriverServer.exe");
    WebDriver my_browser;
    my_browser = new InternetExplorerDriver();
    my_browser.get(url);
    Actual_title = my_browser.getTitle();
    if ( Actual_title.contentEquals(title))
        System.out.println(" Test Passed");
    else
        System.out.println(" Test Failed \n Title is "+ Actual_title);
    my_browser.close();
    }
}
DebanjanB

A few words about your script-

With Selenium 3.4.0, IEDriverServer 3.4.0 & IE 10.0.x I don't see any issue within your code but a few points here:

  1. Load a default page http://localhost:44585/ - Yes, that's how IEDriverServer works. We can't help it.

  2. WebDriver my_browser; - As a good programming practice you should keep your code easily understandable for reviews & peer reviews. Hence instance of WebDriver should be driver or something in similar lines.

  3. String title = "Google"; - Here the name of the variable should have been Expected_title which would have been in similar lines of String Actual_title;

  4. Actual_title.contentEquals(title) - You have used if ( Actual_title.contentEquals(title)) as you have observed the Page Title as only "Google". But in most cases you won't be able to see the entire Page Title simply by viewing it. You have to see the page source to observe the entire Page Title. So in your case instead of Actual_title.contentEquals(title) you can use if ( Actual_title.contains(title))so your Testcase doesn't fails.

  5. If you find your code failing while trying to locate elements before the page being loaded, add implicitlyWait to get the page loaded.

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

  1. If you find your code failing while trying to locate elements even after the page being loaded, add explicitWait for an element to be visible in the DOM.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why the driver.getTitle does not matches with the expected result in Selenium?

PL/pgSQL function returns incorrect bitwise result

Array formula with SUM Function returns incorrect result

VBA Atan2 function returns incorrect result

Function giving incorrect result

MySQL MAX returns incorrect result

getTitle() method returns title of current page with Chrome but returns title of previous page with Firefox using Selenium through Java

Selenium Web Driver: NoSuchElementError

Selenium Web Driver Click

scraping with selenium web driver

Selenium Web Driver - Java - TestNG - Assert.assertEquals how to compare actual result with the range between expected result

Date function returning incorrect result

How to click on the second link in google search result list using selenium web driver

Len function returns incorrect results

Python function returns incorrect value

checkPrime function returns incorrect values

File.isFile() returns incorrect result?

Gremlin using select in hasId returns incorrect result

lambdified sympy expression returns incorrect result

getting an array from webservice returns an incorrect result

removing rows without returns incorrect result

Kadane algorithm implementation returns incorrect result

Azure pipeline powershell script returns incorrect result

TimeZoneInfo.ConvertTimeFromUtc returns incorrect result

MarkLogic Query By Example returns incorrect result

Google Maps Autocomplete Place returns incorrect result

in MySQL, MAX() command returns an incorrect result

selenium testNG retry with incorrect result account

Selenium Web Driver (PHP or JAVA)