I am a beginner with Selenium and facing an issue with a task I need to accomplish:
- Go to https://pastebin.com
- Paste "Hello from WebDriver"
- Set the paste expiration to 10 Minutes //Struggling with this step
- Set the paste title as "helloweb"
I am using JavaScript with WebDriver
I can open the dropdown menu, but I am unable to select the expiration time. An error message is displayed:
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>
I realized that the options are hidden within a frame. I tried using the driver.switchTo.frame(driver.findElement(xpath)) function
Below is the code snippet I am using:
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();
}
})();
However, I encountered an error stating "driver.switchTo.frame is not a function". Can someone please assist me in resolving this issue? Thank you.