The function driver.switchTo.frame() does not exist

I am a beginner with Selenium and facing an issue with a task I need to accomplish:

  1. Go to https://pastebin.com
  2. Paste "Hello from WebDriver"
  3. Set the paste expiration to 10 Minutes //Struggling with this step
  4. 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.

Answer №1

Update the code by removing the .click() method from the switch to frame line.

await driver.switchTo.frame(driver.findElement(By.xpath('//*[@id="postform-expiration"]/option[3]')));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Derive the property type based on the type of another property in TypeScript

interface customFeatureType<Properties=any, State=any> { defaultState: State; properties: Properties; analyzeState: (properties: Properties, state: State) => any; } const customFeatureComponent: customFeatureType = { defaultState: { lastN ...

Trouble With Ajax Submission in CakePhp: Issue with Form Serialization

In my attempt to utilize ajax for sending an array of objects along with serialized form data, I encountered a problem. The issue arises when I include the array in the ajax data along with the serialized form data. This results in the serialized form data ...

Establishing Node.js environment variables when invoking `npm run` command

package.json { "scripts": { "start": "NODE_ENV=development node ./index.js" } } If we wanted to pass and override NODE_ENV when running npm run start, is it possible? npm run start NODE_ENV=production ...

The PHP page is not receiving the variable passed through AJAX

Within the following code snippet, there seems to be an issue with accessing the dataString variable in the comment.php page. To retrieve the variable name, I utilized $_POST['name']. $(document).ready(function(){ $("#submit").click( function() ...

Bootstrap form validation solution

Utilizing bootstrap validation to validate a jsp page. The folder structure is as follows: WebContent ├── bootstrap-form-validation ├── js └── pages All three folders are under the web content. If I create another folder called teacher ...

Obtain user input and showcase it on the screen using a combination of Ajax and PHP

Whenever a user inputs a value in the textbox, it should dynamically display on the screen. I have successfully implemented this feature once, but I am encountering difficulties with implementing it for a second input. Your help is greatly appreciated. fu ...

Adding Angular dependencies through Gulp (with the help of Browserify)

Exploring the use of Gulp and Browserify in my new Angular application. Inquiry: How can I effectively include angular dependencies in the app.js file without encountering dependency errors? Even with minimal dependencies, such as using only $stateProvid ...

Iterating over an array of lists to tally the elements

I've been struggling to count the number of objects in an array using JavaScript. Below is the array I'm trying to work with: <script> var arr = [ {"gateways":["ccu1"],"manufacturer":["homematic"],"ir":["ir_no"],"ip":["ip_cam", ...

Error: Attempted to export 'e', however it was not defined in the module (located at vite.js?v=d59cec13:236:3) - occurring in the three.js/vite combination

After dabbling in javascript, I decided to explore three.js and found it quite intriguing. However, after hours of setting everything up, I encountered a roadblock. When I attempted to create geometry and render it, the code stopped working. Upon investiga ...

Beware: The use of anonymous arrow functions in Next.js can disrupt Fast Refresh and lead to the loss of local component state

I am currently encountering a warning that is indicating an anonymous object in a configuration file, and even specifying a name for it does not resolve the warning. Below you will find the detailed warning message along with examples. Warning: Anonymous ...

What seems to be the issue with my snake game not loading properly?

I am having trouble getting something to display in my browser while working on this snake game. No matter how many times I check, I can't seem to find the mistake I made. Every time I refresh the browser, the screen remains blank. gameTime.html < ...

What are the steps to successfully install OpenCV (javascript edition) on Internet Explorer 11?

I'm currently experiencing issues with getting the OpenCV javascript version to function properly on IE11 for contour detection. While my code runs smoothly on all other up-to-date browsers, I am encountering errors such as: TypeError: Object doesn&a ...

axios does not distinguish between response and error in its return value

I have created a React component that contains a function called onFormSubmit. This function calls another function from a separate component, which in turn makes a POST request using axios. I want the ability to return a response if the POST request is su ...

Unable to trigger JQuery .blur event

I am currently working on implementing server-side validation for an input field that needs to be validated when it loses focus. However, I'm running into an issue where the alert is not triggered when the input field loses focus. Here's a snipp ...

The Ajax script triggers the PHP script twice

Utilizing AJAX on my HTML page, I am able to dynamically load data from a MySQL database without reloading the page and send email notifications upon certain events. The process involves Ajax calls to script.php which then makes requests to the database an ...

To enable Android permissions while testing with BrowserStack Automate using Selenium and Appium, simply click on the permission prompts

We are currently developing an automated test suite using BrowserStack Automate for our tests in Selenium with Appium. One particular test requires us to play DRM protected content which works fine on desktop platforms, but we are facing challenges testin ...

I'm receiving a Reference Error stating that 'next()' is not defined, despite the fact that I have defined it in my JavaScript code. What could be causing this issue?

I have a javascript function called next() to process information and then call the function from HTML. However, my Firefox console is showing a ReferenceError: 'next' is not defined. I am aware that there is an error in my code, but I cannot pin ...

issue with JavaScript canvas

My task is to develop a Blackberry application, but I have limited knowledge in Java. Since the application requires drawing capabilities, I decided to use HTML5 and JavaScript instead. I started reading some JavaScript tutorials to prepare for this proj ...

JavaScript animation for sequencing traffic lights

I have been working on completing a task that was assigned to me. (iii) Explain the organization of an array that could manage the traffic light sequence. (iv) Develop a script that utilizes the array outlined in part (iii) to create an animated display ...

Enable automated addition or alteration of phone numbers through Twilio's API

I'm looking to programmatically add and edit phone numbers using the API on this Twilio link. Can you guide me on how to achieve this? ...