Reputation: 435
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:
Upvotes: 0
Views: 330
Reputation: 16201
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();");
Upvotes: 1
Reputation: 435
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();
Upvotes: 1