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

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"

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)

Related

How to get selenium to scroll to an element (Typescript)?

I'm using jest and selenium. I recently ran into an issue where a sticky footer I have is blocking the element I want to click on. I get the error: 'ElementClickInterceptedError: element click intercepted: Element is not clickable at point (988, 1108)'.
I have tried adding a function =>
this.driver.executeScript("arguments[0].scrollIntoView ;", element);
}
but I get this error: 'JavascriptError: javascript error: arguments[0].scrollIntoView is not a function'.
How do I get selenium to scroll to an element so I can click it using typescript/jest?

selenium webdriver find_element_by_xpath

I am trying to click on the accept button using xpath in www.simulator.betfair.com but it keeps giving me the error down below
selenium.common.exceptions.NoSuchElementException: Message: no such
element: Unable to locate element:
{"method":"xpath","selector":"//*[#id="onetrust-accept-btn-handler"]"}
(Session info: chrome=90.0.4430.85)
Any ideas? this is my code
from selenium import webdriver
url = r"C:\Users\salde\Desktop\chromedriver_win32 (1)\chromedriver.exe"
driver = webdriver.Chrome(executable_path=url)
driver.get('https://simulator.betfair.com/')
cookies = driver.find_element_by_xpath('//*[#id="onetrust-accept-btn-handler"]')
cookies.click()

Selenium: Unable to locate email type box, not within any iframe

I am trying to detect the login id and password field of a website : https://mretailstore.com/login but seems selenium is not able to locate the email type box. I have checked stackoverflow but didn't get any solution to this. Someone has used iframe because of what he/she was facing the same issue but here we have not incorporated any iframe.
The error I am getting is:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: .//*[#id='identity']
The code I am using:
System.setProperty("webdriver.gecko.driver", "C:\\Users\\MI SERVICE\\Downloads\\geckodriver.exe");
FirefoxOptions capa = new FirefoxOptions();
capa.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capa);
driver.get("https://www.mretailstore.com/");
driver.findElement(By.xpath(".//*[#id='identity']")).sendKeys("abc#d.com");
driver.findElement(By.xpath(".//*[#id='password']")).sendKeys("abc123");
driver.findElement(By.id("loginbutton")).click();
driver.navigate().back();
driver.close();
It looks your xpath is correct only and this exception is happening before element rendering.So, Please add the some explicit wait after the page loading.
It is working for me with/without Explicit Wait.
Code:
driver.get("https://www.mretailstore.com/");
WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.titleIs("Login"));
driver.findElement(By.xpath(".//*[#id='identity']")).sendKeys("abc#d.com");
driver.findElement(By.xpath(".//*[#id='password']")).sendKeys("abc123");
driver.findElement(By.id("loginbutton")).click();

Unable to get the text of an element usng selenium web driver in Jasmine test cases

I need to get the text value of an element using selenium web driver as follows.
this.driver.findElement(selenium.By.id('floor-name')).then(function(element){
expect(element.getText()).toMatch("Floor 1");
})
I am using following versions of libs
node v6.2.1
selenium-webdriver 2.53.2
jasmine v2.4.1
jasmine-core v2.4.
1
This is the error I am getting while running the test
Message:
Expected ManagedPromise::370 {[[PromiseStatus]]: "pending"} to match 'Floor 1'.
Stack:
Error: Expected ManagedPromise::370 {[[PromiseStatus]]: "pending"} to match 'Floor 1'.
at /home/tharsan/tmp/selenium/spec/cleanViewSpec.js:46:27
at ManagedPromise.invokeCallback_ (/home/tharsan/tmp/selenium/node_modules/selenium-webdriver/lib/promise.js:1379:14)
at TaskQueue.execute_ (/home/tharsan/tmp/selenium/node_modules/selenium-webdriver/lib/promise.js:2913:14)
at TaskQueue.executeNext_ (/home/tharsan/tmp/selenium/node_modules/selenium-webdriver/lib/promise.js:2896:21)
Where are you passing the element here? you have to resolve the getText promise. Try this:
this.driver.findElement(selenium.By.id('floor-name')).getText().then(function(text){
expect(text).toMatch("Floor 1");
});

How to use gethtmlsource or storeHtmlSource in Selenium Webdriver(Java)?

i want to print html page source in output. In selenium IDE there is a command to perform this action.
storeHtmlSource
How to do the same in Selenium Webdriver(Java)?
While exporting the testcase, It shows the following error.
// ERROR: Caught exception [ERROR: Unsupported command [getHtmlSource | | ]]
Using Selenium WebDriver:
WebDriver driver = new ChromeDriver();
driver.get("your Url here");
String htmlSource = driver.getPageSource();
Api doc to get the page source
https://seleniumhq.github.io/selenium/docs/api/java/