简体   繁体   中英

How to click on a flash object

I need to click on a flash object. This is my javascript code below, currently, which is not working. I am not too familiar with js, hence, please bear with me.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.querySelectorAll('a[title='Banner - Flash']').click();");

A screenshot of the page html:

在此处输入图片说明

It turned out that I needed to grab an iframe. The code below works just fine!!!

driver.switchTo().frame("rmf_iframe");
driver.findElement(By.xpath("//a[contains(@href, 'javascript:gotoAdFormat(130);')]")).click();

You need to use querySelector() not querySelectorAll() . querySelectorAll() is plural and hence it returns all elements matching the cssSelector . You also have to be careful about the selector and make sure it returns ONLY the intended element.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.querySelector('a[title='Banner - Flash']').click();");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM