I am having problems with clicking an element in a dropdown. What i have to do is:
However, after opening the dropdown some 3rd party ad content doesn't let me click my button, which results in ElementClickInterceptedError
Here is my code
const {Browser} = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');
(async function example() {
let driver = await new Builder().forBrowser('chrome').build();
driver.manage().window().maximize();
try {
await driver.get('https://pastebin.com');
await driver.findElement(By.xpath('//*[@id="postform-text"]')).sendKeys('Hello from WebDriver');
await driver.findElement(By.xpath('//*[@id="w0"]/div[5]/div[1]/div[2]/div/span/span[1]/span')).click()
await driver.findElement(By.xpath("//*[@id=\"select2-postform-expiration-results\"]/li[3]")).click();
await driver.findElement(By.xpath('//*[@id="postform-name"]')).sendKeys('helloweb');
finally {
// await driver.quit();
}
})();
The error message im getting:
ElementClickInterceptedError: element click intercepted: Element <span class="select2-selection select2-selection--single" role="combobox" aria-h
aspopup="true" aria-expanded="false" tabindex="0" aria-disabled="false" aria-labelledby="select2-postform-expiration-container">...</span> is not
clickable at point (301, 605). Other element would receive the click: <iframe frameborder="0" src="https://5c552a9e567bcd9a4394df1b9acbfaaa.safe
frame.googlesyndication.com/safeframe/1-0-38/html/container.html" id="google_ads_iframe_/22653346938/12825_Pastebin.com/12825_Pastebin.com_SmartB
anner_1_0" title="3rd party ad content" name="" scrolling="no" marginwidth="0" marginheight="0" width="970" height="90" data-is-safeframe="true"
sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" role="r
egion" aria-label="Advertisement" tabindex="0" data-google-container-id="3" style="border: 0px; vertical-align: bottom;" data-load-complete="true
"></iframe>
You can use the below locator to click on Paste Expiration: dropdown
CSS_SELECTOR
#select2-postform-expiration-containe
After that to choose option 10 minutes you can use this locator
Xpath
//li[contains(.,'10 Minutes')]
I have tested this using Java and it's working for me.
In case you are unable to click on Paste Expiration: drop than use Actions method to move_to_element and click on it.