I am new to Selenium. Here is the task:
I am using javascript, with chromedriver
I am able to open the dropdown but cant choose the expiration time, it says:
ElementClickInterceptedError: element click intercepted: Element <span class="select2-selection__arrow" role="presentation">...</span> is not clickable at point (422, 569). Other element would receive the click: <iframe frameborder="0" src="https://9c4fe1b6ba8be5733ce3e7442f84515f.safeframe.googlesyndication.com/safeframe/1-0-38/html/container.html"
id="google_adsiframe/22653346938/12825_Pastebin.com/12825_Pastebin.com_SmartBanner_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="region" aria-label="Advertisement" tabindex="0" data-google-container-id="1" style="border: 0px; vertical-align: bottom;" data-load-complete="true"></iframe>
So i found out that the choices are hidden inside a frame(i am new to this). I used driver.switchTo.frame(driver.findElement(xpath)) function
Here is my code:
const { Browser } = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');
const { waitForServer } = require('selenium-webdriver/http/util');
(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/span[2]')).click()
await driver.switchTo.frame(driver.findElement(By.xpath('//*[@id="postform-expiration"]/option[3]'))).click()
await driver.findElement(By.xpath('//*[@id="postform-name"]')).sendKeys('helloweb');
await driver.findElement(By.xpath('//*[@id="w0"]/div[5]/div[1]/div[8]/button')).click();
}
finally {
await driver.quit();
}
})();
But it says "driver.switchTo.frame is not a function". How can i fix this? Please help
Remove .click() from switch to frame line code.
await driver.switchTo.frame(driver.findElement(By.xpath('//*[@id="postform-expiration"]/option[3]')));