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?
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.
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.
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.
Click on the “console” tab. In the console, type “document. URL” command and hit enter. You will give the current URL.
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
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