Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the current URL of a webpage in selenium-webdriver

I am using selenium webdriver to do some automation on browser. now there is a need to get the current url of the page currently opened in the browser.

I wrote the below code but giving me error:

element = driver.find_element :name => "btnSearch"
element.click

all_table_data = driver.find_elements(:tag_name, "td")

 all_table_data.each do |td|

   puts td.text

 end

 print driver.get_url

But it is giving me an error:

filedownload.rb:30:in `<main>': undefined method `get_url' for #<Selenium::WebDr
iver::Driver:0x4292df26 browser=:firefox> (NoMethodError)

Can anyone help me here to fix it?

like image 518
DoLoveSky Avatar asked Jan 20 '13 20:01

DoLoveSky


People also ask

How do you get the current page URL in Selenium?

To get the the current URL of web page programmatically using Selenium in Java, initialize a web driver and call getCurrentUrl() method on the web driver object. WebDriver. getCurrentUrl() method returns a string representing the current URL that the browser is looking at.

Why we use Get current URL command in Selenium?

Get Current URL Command In WebDriver, this method fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a String value.

How do I get current URL in Selenium WebDriver using Python?

You can easily get the current URL of a web page when performing Python automation testing — to do that, you just need to access the current_url method of the Selenium WebDriver object.

Which of the following in Selenium is used to get current URL using Javascript?

Click on the “console” tab. In the console, type “document. URL” command and hit enter. You will give the current URL.


1 Answers

Try driver.current_url instead of get_url.

https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/zzP5IDgxP5A

Documentation for the Selenium::WebDriver::Driver class:

http://rubydoc.info/gems/selenium-webdriver/2.9.1/Selenium/WebDriver/Driver

like image 188
Josh Rieken Avatar answered Oct 03 '22 04:10

Josh Rieken