0 votes
1 view
in Devops and Agile by (19.8k points)

I'm attempting to get the URL of the currently open page. I am using Selenium WebDriver and Java.

I am accessing the current URL via:

WebDriver driver = new WebDriver();

String url = driver.getCurrentUrl();

however, the URL does not appear to actually reflect where I currently am.

My current test case involves going to the NYT website and then clicking on the "Technology" link. However, the URL appears to always be http://www.nytimes.com/, regardless of the URL that is displayed in the address bar.

How do I actually access the value of the URL that's in the address bar so I can tell what page I'm actually on?

1 Answer

0 votes
by (63.4k points)

Put sleep. It will work.

time.sleep(“Seconds_as_per_your_wish”);

I think this is the single reason that the page wasn't getting loaded. 

I am assuming that you may need some reference for “Wait for page load in Selenium”, you can check the below code to know how to wait for the load.

In my case, I used the following to know the page load status. In our application loading gif(s) are present and, I listen to them as follows to eliminate unwanted wait time in the script.

public static void processing(){

WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='Msgpanel']/div/div/img")));

wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@id='Msgpanel']/div/div/img"))); }

Where the xpath locates the gif in the HTML DOM. After this, You may also implement your action methods Click.

public static void click(WebElement elementToBeClicked){

WebDriverWait wait = new WebDriverWait(driver, 45); wait.until(ExpectedConditions.visibilityOf(element)); wait.until(ExpectedConditions.elementToBeClickable(element)); wait.ignoring(NoSuchElementException.class).ignoring(StaleElementReferenceException.class); elementToBeClicked.click();

}

If you want to Learn What is Selenium visit this Selenium Tutorial by Intellipaat.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...