I am trying to click on "Add payment method" button under Payment Methods tab using selenium - https://pay.google.com/gp/w/home/paymentmethods

Tried using xpath, className and cssSelector but looks like something is wrong with the code. :(

Not sure where I am going wrong. Can someone please try? :(

  • Thanks so much for the help, Niels! Greatly appreciated! I figured this but couldn't find the right frame id so thanks for the frame id. Tried this code but it still doesn't click: Driver.switchTo().frame("<iframe frameborder=\"0\" src=\"about:blank\" id=\"mainWidget_:0Iframe\" name=\"mainWidget_:0Iframe\">\n" + ""); Driver.findElement(By.xpath("/html/body/div[3]/div[2]/div/a/div/div/span")).click(); Thread.sleep(2000); Could you please try this? Am I doing something wrong? :( Thanks again!
    – Khyati
    Apr 23, 2020 at 9:03
  • Please share the code of what have you tried before? Why do you think there is something wrong - are you getting some errors? Please, share those as well.
    – Mate Mrše
    Apr 23, 2020 at 9:15
  • This doesn't belong to "answers" section. Please update the original question with this information.
    – Mate Mrše
    Apr 23, 2020 at 9:16
  • Added a bit of example code to my answer, but why put in "\n" + "" as the framename? Makes no sense. Also do not use absolute paths to find elements, very unmaintainable. Apr 23, 2020 at 9:39

2 Answers 2


The Add Payment Button is part of a frame, you first need to switch to the frame before trying to find the element.

The frame:

<iframe frameborder="0" src="about:blank" id="mainWidget_:0Iframe" name="mainWidget_:0Iframe">


Example code:

WebElement frame = driver.findElement(By.id("mainWidget_:0Iframe"));
WebElement paymentButton = driver.findElement(By.xpath("//span[contains(text(), 'Add payment method')]"));

Maybe you also need to wait for the frame/button to load.


I reached out to Payment team and they confirmed that there are a few a11y and keyboard issues (focus,aria labels, landmarks and title attributes) which are known and prod issues which they will fix mostly by end of this year. And this was the reason why I was not able to move the focus to the frame and from there click on "add payment method" button. The frames do not even have a unique label which is mandatory.

In a nutshell, the prob is with the site, not with the code! :)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.