No element found error with selenium-webdriver

For the below code I am getting error as “no element found”

if download_field_name == “form :”

if (download_link =~ /fileEntityId=\d+/) != nil

#driver.find_element(:link, link_text).click
puts @extension
puts link_text
driver.find_element(:link, link_text).click if
[".pdf",".gif",".bmp",".tif",".jpeg",".jpg"].include?(@extension)

end

end


===========================================
C:\Documents and Settings\My Documents\userdata\Ruby\Scripts>dwonloadv4
.rb
.bmp
Gaurav Kapoor BR.bmp
.txt
Timothy L. Casbeer W9.txt
.bmp
Jason Mattiace BR.bmp
.docx
Reimbursements.docx

Are the below text is culprit - “Gaurav Kapoor BR.bmp” - this is
present in the webpage, but above code is saying not found.

You have 2 spaces in that link name.
Also you’re not doing any checks to ensure that the name you provide
actually exists.

I did check but for some of the files it is happening. Those are present
in the webpage. But instead clicking throwing errors:

here is the code:

if download_field_name == “form :”

if (download_link =~ /fileEntityId=\d+/) != nil

#driver.find_element(:link, link_text).click
puts @extension
puts link_text

begin

driver.find_element(:link, link_text).click if
[".docx",".doc",".pdf",".gif",".bmp",".tif",".jpeg",".jpg",".txt"].include?(@extension)

rescue => e

wbs.cells(rows,4).value = link_text

raise

end

end

end

Yes, There is two spaces but How should I handle this on the page,as the
webpage is read only. I am just downloading files which has the
extensions match only. But above mentioned files are not only
downloaded,whereas they present there.

Don’t know why - driver.find_element(:link, link_text).click not
worked when string within the link_text has more than one spaces
between words. But anyway workaround I found is :

link_text.squeeze!(" ").strip! # to remove multiple spaces

If you want multiple spaces in HTML to be displayed as such, you need to
use non-breaking spaces: “&nbsp” in HTML.

Joel P. wrote in post #1099119:

If you want multiple spaces in HTML to be displayed as such, you need to
use non-breaking spaces: “&nbsp” in HTML.

Didn’t understand you. BTW link_text is the file names to be downloaded
from the webpage. webpage is from third party. And I managed it by using
strip and squeeze. Don’t know why the driver couldn’t find out
with in between multiple spaces.

Thanks

This is a well known feature of HTML and has information available all
over the internet. Here’s one example:

http://codes.codedigest.com/CodeDigest/76-Display-multiple-spaces-in-HTML.aspx

Joel P. wrote in post #1099125:

This is a well known feature of HTML and has information available all
over the internet. Here’s one example:

http://codes.codedigest.com/CodeDigest/76-Display-multiple-spaces-in-HTML.aspx

Thanks Joel :slight_smile: for sharing the link for my self learning. :slight_smile:

Amway long days no see. :slight_smile:

You might want to look into this for dealing multiple spaces in your
input:

http://www.ruby-doc.org/core-2.0/String.html#method-i-squeeze

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs