click by-link-text

53 views
Skip to first unread message

Richard East

unread,
Oct 6, 2014, 7:12:43 AM10/6/14
to clj-we...@googlegroups.com

Hi,

I’m new to using clj-webdriver. I am using it with lein–cucumber. I am trying to create a “Given” for clicking on links on my site based on the text the user sees in the link.

Here’s what’s I’ve got:

(require '[clj-webdriver.taxi :as taxi]

         '[clj-webdriver.core :as core]

         '[myproject.browser :refer [browser-up browser-down]]

         '[clojure.test :refer :all])

 

(Given #"^I click on \"User Profiles\"$" []

      (taxi/click "a[href*='/profiles']"))         ;; This works, but I have to write a given for every link.

 

(Given #"^clicking on \"([^\"]*)\"$" [link_text]

    (taxi/click (core/by-link-text link_text))) ;;This won’t work, because by-link-text doesn’t return a string.

 

Can you recommend the best way to click on a link by link text?

 

Regards,

 

Richard

semperos

unread,
Aug 15, 2015, 8:35:37 AM8/15/15
to clj-webdriver
Richard -- I know this is impossibly late to be of any use, but I'll respond anyway.

The `by` functions are low-level wrappers around the By class in Selenium-WebDriver. They're designed to be used by the corresponding lower-level find-element functions that themselves are just wrappers around the methods of WebElement, which accept these By objects.

You can find elements by text first and then click them, or you can try to use XPath and include a text query. Here's an example of finding an element using the Core API:

(click (find-element driver {:tag :a :text "Text I Care About"}))

-Daniel

Richard East

unread,
Aug 28, 2015, 10:37:29 AM8/28/15
to clj-we...@googlegroups.com

Hi Daniel,

Thank you. I'll use this for the future. I greatly appreciate your reply – it's very helpful. It'll reduce a lot of tests for me.


--
You received this message because you are subscribed to a topic in the Google Groups "clj-webdriver" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clj-webdriver/EIxeX91nT3M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clj-webdrive...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages