Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Click on an element by aria_label

synthetics-script

#1

Hi,

I need to click on an element that every time the page is reloaded this element changes its position.

Example:

<div class="bc-keyboard" role="button" tabindex="0" aria-label="5" aria-pressed="false">0</div>

I tried this:

$browser.findElement($driver.By.partialLinkText("0")).click()

$browser.findElement($driver.By.linkText("0")).click()

but none worked, can i capture this element by the aria_label, or some other method ?

Regards


#2

Hi, @julian.valencia: Yes, you may use a CSS selector:

$browser.findElement($driver.By.css('div[aria-label="5"]')).click();

#3

Hi Philweber,

I have another problem.

I have these elements:

<div border="0" id="VgoFuTOgPVhx1" valign="center" align="center" onfocus="this.blur();" class="colorContrast2" style="font-weight: bolder;">1</div>

<div border="0" id="EUUXTUxxKGOy8" valign="center" align="center" onfocus="this.blur();" class="colorContrast2" style="font-weight: bolder;">8</div>

I need to click on these elements, but the id and xpath always change, how do I capture it?

does not work with: $browser.findElement($driver.By.linkText("1")).click();

Thanks For you help.

Regards.


#4

Hi, @julian.valencia: Yes, linkText() only works with links ('a' tags), not divs. Have you tried:

$driver.By.xpath(//div[text()='1']);