0

I am new here and even to Ruby and Selenium. I am trying to click a link on web page which has following code:

<a> target="mainFrame" href="dynamic_Utility_Index.htm">Dynamic Utilities</a>

So basically I want to click on this dynamic utilities. The script which I have written so far is:

    require 'selenium-webdriver'
    require 'win32ole'

    driver = Selenium::WebDriver.for:firefox
    driver.manage().window().maximize();

    driver.navigate.to 'xyz.com'

    wait = Selenium::WebDriver::Wait.new(:timeout =>10) # seconds

    #Click on Dynamic Utilities
    wait.until{driver.find_element(:link_text,'dynamic_Utility_Index.htm').click}
    puts "Clicked"

I have even used link, partial_link_text in place of link_text but keep getting the following error

(Unable to locate element: {"method":"link text","selector":"dynamic"}) (Selenium::WebDriver::Error::TimeOutError)

I am using Ruby and Selenium Web driver.

2
  • 1
    Can you check if this link is located inside an iframe? Thanks. Commented Apr 27, 2016 at 14:04
  • No its not loctaed within iframe Commented Apr 28, 2016 at 9:26

2 Answers 2

1

Did you try with:

wait.until{driver.find_element(:link_text,'DYNAMIC UTLITIES').click}

?? Sometimes I had to use the text link by capitalized.

Another option could be:

driver.find_element(:xpath, "//a[contains(@target, 'mainFrame')]").click

Hope works for you :D

Sign up to request clarification or add additional context in comments.

3 Comments

Tried both, still getting same error..btw thanks for the help
@JimitShah: Maybe... as a "debug" mode.... you could do this: puts driver.find_elements(:link_text,'DYNAMIC UTLITIES').length or puts driver.find_elements(:xpath, "//a[contains(@target, 'mainFrame')]").length to see if at least we are able to reach the element. If this give us at least 1 element we can start "playing" with click or text methods.
I tried both in my code. Its prints 0 in both the case.
0

The item you consider to be a link text (dynamic_Utility_Index.htm) actually just a value of href attribute. Actual link text is "Dynamic Utilities". Also you can use xpath locator //a[@href="dynamic_Utility_Index.htm"] instead of search by link text:

wait.until{driver.find_element(:xpath,'//a[@href="dynamic_Utility_Index.htm"]').click}

6 Comments

So you mean like this wait.until{driver.find_element(:xpath,'/html/body/table/tbody/tr[11]/td[2]/a[@href="dynamic_Utility_Index.htm"]').click} wait.until{driver.find_element(:xpath,'/]/a[@href="dynamic_Utility_Index.htm"]').click} Tried both..same error..Unable to locate element
Does wait.until{driver.find_element(:link_text,"Dynamic Utilities").click} works?
So i even used wait.until{driver.find_element(:xpath,'//a[@href="dynamic_Utility_Index.htm"]').click}
No It doesn't works, that what i am stuck with..its pretty simple..but i am not able to crack it
Are you sure that you provided correct HTML for target element? It looks like <a>...>...</a>, but should looks like <a...>...</a>. Maybe you remove something in provided HTML code sample
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.