MK Mou
MK Mou

Reputation: 29

How to get a response with Selenium when a click() is sent to server? True or False status output

How should I check if the following is working? What can I do, to get a true or false response?

 driver.find_element_by_link_text("XXXX").click()

Upvotes: 0

Views: 1018

Answers (2)

Rajendra Kumbar
Rajendra Kumbar

Reputation: 7

Clicking on a link typically takes you to another window/tab. You can capture the title/url of that page and assert that click operation worked

try:
    ele=driver.find_element_by_link_text("XXXX")
    if (ele):
        print "this link exists in the page"
except:
    print("there is no such link in the page")

Upvotes: 1

cruisepandey
cruisepandey

Reputation: 29362

let's say when you fire a .click event, a event occurs in UI (for an example after clicking on login button, we see dashboard page title or heading) what we would do in this case is to assert that heading, or title, if assertion works then script will get to know that the previous .click was actually done, cause if it was not then assertion would have failed.

try:
    driver.find_element_by_link_text('some text').click()
    # put some delay here, WebDriverWait or time.sleep()
    assert driver.find_element_by_xpath('dashboard page heading web xpath here').text in "expected dashboard heading"
    print('Assertion worked so .click was correct')
except:
    print('Assertion must have failed')

Upvotes: 1

Related Questions