Ossz
Ossz

Reputation: 364

Using selenium to click a button

For clicking a button with the following HTML code:

<a href="javascript:submitPage('V','All Notes','');" class="viewFilter">All Notes</a>

I have tried multiple ways to click/ access this button but to no success, for example:

all_notes = wait.until(EC.presence_of_element_located((By.XPATH, "//a[@href='javascript:submitPage('V','All Notes','');']"))).click()

all_notes = wait.until(EC.presence_of_element_located((By.XPATH, "//href[@type='class' and @value='View All']"))).click()

I am not really sure what the issue is here - for all other button presses on this webpage - selenium has been working appropriately. What other ways can I try?

Upvotes: 0

Views: 216

Answers (2)

PDHide
PDHide

Reputation: 19939

all_notes = WebDriverWait(driver,10).until(EC.presence_of_element_located(
    (By.XPATH, '//*[@href="javascript:submitPage(\'V\',\'All Notes\',\'\');"]'))).click()

escape the single quotes

Upvotes: 1

Nicholas_Jones
Nicholas_Jones

Reputation: 330

Try this Xpath...

//a[@class='viewFilter' and contains(text(), 'All Notes')]

What this does is verifies that the class is viewFilter and since classes can appear more than once also ensure that the link text is All Notes.

Upvotes: 1

Related Questions