2

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? :(

4
  • 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 '20 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 '20 at 9:15
  • This doesn't belong to "answers" section. Please update the original question with this information.
    – Mate Mrše
    Apr 23 '20 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 '20 at 9:39
1

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">

Reads:

Example code:

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

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

1

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, privacy policy and cookie policy

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