Getting the following error when clicking on Login button with webdriver: Request failed due to element click intercepted - webdriver-io

When clicking on the login button using below XPATH getting following error: Request failed due to element click intercepted, see below image of HTML code:
XPATH:
('//*[#id="btnLogin"]');
('//a[#id="btnLogin"]');
('#btnLogin');
('//a[#id="btnLogin"]/text()');
('//a[contains(#id, "btnLogin")]');
('//a[#id="btnLogin" and #class = "big-button lnkbuttonlogin"]');

//*[#id='btnLogin']
//a[#id='btnLogin']
Above locators should work , press F12 . go to elements tab
.Type ctrl +F and search for matching nodes using above locators .
Alternatively , Try clicking using a Javascript .
import org.openqa.selenium.JavascriptExecutor;
String idloc="btnLogin";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('"+idloc+"').click();");

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?

AttributeError: module 'selenium.webdriver' has no attribute 'switch_to_alert'

I am making a simple crawler that can open a site and when a pop up appears, it should close it. but the following command isn't working.
from selenium import webdriver
browser = webdriver.Chrome(executable_path=r"C:\Program Files\chromedriver.exe")
url = "https://www.bnbaccessories.com/"
browser.get(url)
alert = webdriver.switch_to_alert().dismiss()
innerHTML = browser.execute_script("return document.body.innerHTML")
browser.implicitly_wait(50)
browser.close()
Use this
alert = browser.switch_to.alert.dismiss()
instead
webdriver.switch_to_alert().dismiss()
driver instance name is browser not webdriver

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();

When I click on link under menu which is inside the iframe, it opens the new browser window

In below code of selenium script to access iframe elements.
I open a menu in first webElement and and then in second webElement I click on link watches under menu.
It redirects the page properly but it opens same page in new browser window also.
i.e. 2 browser are opened. How to prevent new browser to be opened.
driver.switchTo().frame(driver.findElement(By.id("watches_iframe")));
Thread.sleep(3000);
WebElement menu = driver.findElement(By.xpath("//div[#id='pm-
nav']//div[#class='pm-menu-button']"));
menu.click();
// when I click on below link it redirects the page properly but opens same
// page in new window also
WebElement store = driver.findElement(By.xpath("//div[#id='pm-menu-
master']//li[#class='item-store']//a//span[1]"));
store.click();

Selenium - How to Click a Link by href value in WebDriver

I have this piece of code
<a href="/iot/apply/device.do" id="subMenu1" class="fortification55"
onclick="$('#deviceinfo').hide()">Apply</a>
I am trying to link by href using
getDriver().findElement(By.name("subMenu1")).click();
But i got this error
org.openqa.selenium.NoSuchElementException: Unable to find element with name == subMenu1 (WARNING: The server did not provide any stacktrace information)
As the element is having the onclick Event, the WebElement is a JavaScript enabled element. So to invoke click() on the element you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
Using cssSelector and only href attribute:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[href='/iot/apply/device.do']"))).click();
Using xpath and only href attribute:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#href='/iot/apply/device.do' and text()='Apply']"))).click();
Using a canonical cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.fortification55#subMenu1[href='/iot/apply/device.do']"))).click();
Using a canonical xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='fortification55' and #id='subMenu1'][#href='/iot/apply/device.do' and text()='Apply']"))).click();
Note : You have to add the following imports :
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.By;
References
You can find a couple of relevant discussions on NoSuchElementException in:
NoSuchElementException, Selenium unable to locate element
Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[#id='login-email']
the following code should work :
By.xpath("//a[#href='/iot/apply/device.do']")