element not interactable: element has zero size- Java Selenium - selenium

I'm writing code to test the facebook website login feature. My chrome browser successfully launches and can enter user and password but I'm unable to select the 'Accept All' button when the test first goes on the website for the cookies.
My code goes onto Facebook.com then tries to find the accept all button. But I can get exception
element not interactable: element has zero size
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[#id=\"facebook\"]/body")).click();
Below is the output of inspect
<button value="1" class="_42ft _4jy0 _9o-t _4jy3 _4jy1 selected _51sy" data-cookiebanner="accept_button" data-testid="cookie-policy-banner-accept" title="Accept All" type="submit" id="u_0_j_wR">Accept All</button>

//button[.='Accept All']
As well as adding a webdriver wait would solve your issue.

Related

Link Click using selenium webdriver is giving timeout error, link is working fine on browser otherwise

I'm trying to write a piece of code using Testng in selenium, the problem is when i try to click a link, the code becomes unresponsive and gives error- Timed out receiving message from renderer
Tried driver.get("https://infostore.saiglobal.com/") instead of driver.findElement(By.linkText("Infostore")).click(); still remains unresponsive - Doesnot get directed to the webpage - https://infostore.saiglobal.com/
#Test
public void testSai() throws Exception {
driver.get("https://www.saiglobal.com/"); //open homepage
driver.findElement(By.id("CybotCookiebotDialogBodyButtonAccept")).click(); //accept cookie
driver.findElement(By.cssSelector("#sai-header > div > div.main-nav > div.store-box > div")).click(); //click on Login to open list
sleep(2);
driver.findElement(By.linkText("Infostore")).click(); //click on infostore to be redirected to https://infostore.saiglobal.com/
System.out.println(driver.getCurrentUrl());
Yes I have checked this issue and there is an workaround for this issue if you wish to have this.Try following code.
Take the href attribute value from the link element.
Delete all cookies.
driver.navigate().to(URL);
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + File.separator + "\\Executables\\Chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, 5);
Actions actions = new Actions(driver);
driver.get("https://www.saiglobal.com/");
driver.findElement(By.id("CybotCookiebotDialogBodyButtonAccept")).click();
WebElement element=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='desktop-login']")));
actions.moveToElement(element).build().perform();
WebElement element1=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='desktop-login']/ul/li/a[contains(text(),'Infostore')]")));
String str1=element1.getAttribute("href");
driver.manage().deleteAllCookies();
driver.navigate().to(str1);
System.out.println(driver.getCurrentUrl());
}
This seems to be an error with Selenium that the developers have been dealing with for over a year. They never really give a concrete answer as to what causes it or how to fix it.
The first port of call would be to make sure that your browser and Selenium are compatible. Try opening a different URL that you know works, and if the error persists then there is likely an error with the compatibility of your selenium and web browser. If it works, then there is something wrong with your website.
For reference, I opened your website using Python Selenium, and had no issues loading or interacting with elements. So the error is local to the software you are using.
The issue can also be caused by sleeps(no idea why), so try removing any sleeps and see if this stops the issue.

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

Can not find password input object log in to google with selenium

I am using PhantomJS in selenium for the driver. Here, I find that there is no problem inserting the email address. However, after clicking the next, there should have a input tag named 'password'. But, after waiting, I can not get the required 'password' tag. It shows error not finding the element. Sometimes, I am getting the following error (showing stacktrace):
org.openqa.selenium.InvalidElementStateException: {"errorMessage":"Element is not currently interactable and may not be manipulated","request":{"headers":{"Accept-Encoding":"
Since, I have waited enough time, the following code must work.
Here is the below code snippet for working.
driver.get("https://accounts.google.com/ServiceLoginAuth");
driver.findElement(By.id("identifierId")).sendKeys("xxxxxxxx");
driver.findElement(By.id("identifierNext")).click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password")));
driver.findElement(By.name("password")).sendKeys("xxxxxxxx");
driver.findElement(By.id("passwordNext")).click();
Here is the specific html showing the input field from the google sign in page for email:
input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value=""
The id of Next button is 'identifierNext' and hhe hidden password field:
input type="password" name="hiddenPassword" jsname="RHeR4d" class="yb9KU" tabindex="-1" aria-hidden="true"
After inserting email and click on the next, the input field for the password is:
input type="password" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="current-password" spellcheck="false" tabindex="0" aria-label="Enter your password" name="password" autocapitalize="off" autocorrect="off" dir="ltr" data-initial-dir="ltr" data-initial-value=""
Now, the question is, I have used waiting mechanism for reloading the page so that I can get the password insertion page. But, using Selenium I can not find the named tag of 'password'.
I think the click is not working properly. Is there any chance of not working the click on Next?
Try this:
driver.findElement(By.xpath("//input[1]"));
Or this:
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[#type='password']")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[#type='password']")));
WebElement elementpwd = driver.findElement(By.xpath("//input[#type='password']"));
I hope it helps.
Please find the full code for sending email for Gmail using Selenium Web Driver using Chrome browser
public class Newtest {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tharun\\Desktop\\work\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[#id='gb_70']")).click();
driver.findElement(By.xpath("//*[#id=\'identifierId\']")).sendKeys("*******#gmail.com");
driver.findElement(By.xpath("//*[#id=\'identifierNext\']/content/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//input[#type='password']")).sendKeys("*******");
driver.findElement(By.xpath("//*[#id=\'passwordNext\']/content/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id=\"gbw\"]/div/div/div[1]/div[2]/a")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id=':ir']/div/div")).click();
Thread.sleep(5000);
driver.findElement(By.cssSelector("#\\3a og")).sendKeys("*******#gmail.com");
driver.findElement(By.cssSelector("#\\3a ny")).sendKeys("This is my selenium web driver automation code ");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[#id=\':p3\']")).sendKeys("This is my selenium web driver automation code ");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id=\':no\']")).click();
}
}

Button is not clickable in application and no selenium exception found in console

I'm trying to click on button(which I marked in yellow) using xpath, but it is failing to click and more over no selenium exception found. I tried to click with css selector and ID. Using isdisplayed() - output is true. but with isselected() - output is false.
I Kept Webdriver wait (Visibility, element located, element to be clickable), implicit wait and explicit wait. But nothing is working out.
I'm new to selenium, please help me out
Below are the code
<button id="addNewButton-btnEl" class="x-btn-center" type="button" hidefocus="true" role="button" autocomplete="off" style="height: 19px;">

How to stop page load in Selenium Webdriver

I have logged into an account on one of the websites. After login, a click on a button presents that page, but the page keeps on loading without displaying the next page.
What I wanted is, if the page keeps on loading without giving any response for some time, I need to stop the execution of the script.
I have tried by using the below code, but it didn't work
driver.manage().timeouts().pageLoadTimeout(500, TimeUnit.MILLISECONDS);
If you are using firefox, use firefox profile with selenium and set network.http.connection-timeout to seconds (for ex I am setting it to 10 secs) -
In Java,
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.http.connection-timeout", 10);
For stopping the page-load you can use this
public void stopPageLoading() {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return window.stop");
}