Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing 'ELEMENT' when using switchTo().frame() in javascript

I'm using selenium webdriver with javascript on Chrome and I'm trying to interact with an input inside an iframe like so:

      await driver.switchTo().frame(By.xpath('/html/body/div[1]/div/div/form/ng-form/div/ui-view/div/dqcomponent[3]/ng-form/div[1]/div[1]/iframe/html/body/form/input[1]'));

I am able to use .click() on the element just fine but the above line causes the following error:

(node:4514) UnhandledPromiseRejectionWarning: InvalidArgumentError: invalid argument: missing 'ELEMENT'

I have tried switching to the element using CSS but it produces the same error, how can I properly switch to said iframe?

My webdriver version is ^4.0.0-beta.1 and my chrome driver is ^88.0.0"

like image 254
Iván Hidalgo Avatar asked Apr 08 '26 15:04

Iván Hidalgo


1 Answers

await driver.switchTo().frame expects an element not locator

Use it like

  Elem = await driver.findElement(By.id("some if"))
  await driver.switchTo().frame(Elem)
like image 137
PDHide Avatar answered Apr 10 '26 06:04

PDHide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!