I am attempting to click on the give button under the club sports tab on this page https://givingday.northeastern.edu/pages/giving-page-2.
However, there are 13 give buttons on the page and I only want to select one. Also, a new window appears when you click the button and not sure how to then click the button in that window. Any help is greatly appreciated.
Suppose in below HTML with 3 buttons in it, I want to click second button:
Page HTML:
<div class="campaign-tile-item">
<div class="inline-b">
<div>
<button class="vote-btn primary-color-background">
<img src="...">
<span class="primary-color-background">Give</span>
</button>
</div>
</div>
<div class="inline-b">
<div>
<button class="vote-btn primary-color-background">
<img src="...">
<span class="primary-color-background">Give</span>
</button>
</div>
</div>
<div class="inline-b">
<div>
<button class="vote-btn primary-color-background">
<img src="...">
<span class="primary-color-background">Give</span>
</button>
</div>
</div>
</div>
My current code: (which does not work)
package com.demo.testcases;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.safari.SafariDriver;
public class FirstClass {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new SafariDriver();
String giving1 = "https://givingday.northeastern.edu/pages/giving-page-2";
driver.get(giving1);
Thread.sleep(5000);
driver.findElement(By.xpath("//div/button[text()='Give'][2]")).click();
}
}
<span>inside the button.