lundi 11 novembre 2019

How to click link that contains text

I want to click a link that contains certain text. I have tried using an X-Path expression and that is not working. The application I am testing is Multi Page Application so I am not sure if the new page is generated.

The HTML:

<a class="text-major ev-pick-this-event" href="/cgi-bin/ncommerce3/SEGetEventInfo?ticketCode=GS%3AAMTX%3AHUSKERS%3ASLP2%3A&amp;linkID=BQFN80-AMTX&amp;shopperContext=&amp;pc=&amp;caller=&amp;appCode=&amp;groupCode=SLP&amp;cgc=&amp;dataAccId=129&amp;locale=en_US&amp;siteId=ev_BQFN80-AMTX">HUSKERS - SLP2 - Ranges</a>

What I have tried:

DislplayEventList.js

class DisplayEventListPage {
  async clickEventListLink(page) {
    const slp2ItemLink = await page.$(
      '//a[contains(., "HUSKERS - SLP2 - Ranges")]'
    );
    await slp2ItemLink.click();
  }
}

module.exports = DisplayEventListPage;

navigate.test.js

const path = require("path");
const config = require("config");
const url = config.get("url");
const DisplayGroupListPage = require("../pageObjects/DisplayGroupList");
const DisplayEventListPage = require("../pageObjects/DisplayEventList");

let groupListPage = new DisplayGroupListPage();
let eventListPage = new DisplayEventListPage();

describe("Test Navigation", () => {
  beforeAll(async () => {
    await page.goto(url);
    await page.screenshot({ path: "groupListPage.png" });
    await groupListPage.clickGroupName(page);
    await page.screenshot({ path: "eventListPage.png" });
    await page.waitFor(3000);
    const pageURL = await page.url();
    console.log(pageURL);
    await eventListPage.clickEventListLink(page);
  });
  it('should be titled "evenue 1.5 | Online Ticket Office | HUSKERS - SLP2 - Ranges', async () => {
    await expect(page.title()).resolves.toMatch(
      "evenue 1.5 | Online Ticket Office | HUSKERS - SLP2 - Ranges"
    );
  });
});

Error I receive:

Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': '//a[contains(., "HUSKERS - SLP2 - Ranges")]' is not a valid selector.

Aucun commentaire:

Enregistrer un commentaire