1

I'm trying to automate to log in into salesforce account and after it logs in I want it to click on contact button, but for some reason it won't, I even wrote a different function just for it to click it, but after it logs in it freezes in the same page after the screen maximizes. enter image description here

And this is my code:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;



public class browser {
public static void main(String[] args) throws InterruptedException {
    
    System.out.println("Start Test Case");
    initialize();
    LoginSFDC();
    WrongUNandPW();
    }




private static WebDriver driver = null;

public static void initialize() {
    System.setProperty("webdriver.chrome.driver", "chromedriver");
    driver = new ChromeDriver();
    }



public static void LoginSFDC() throws InterruptedException {
    
    
    driver.get("https://login.salesforce.com/");
    driver.findElement(By.xpath("//input[@id='username']")).sendKeys("[email protected]");
    driver.findElement(By.xpath("//input[@id='password']")).sendKeys("lolboy845JJ");
    
    driver.findElement(By.xpath("//input[@id='rememberUn']")).click();
    driver.findElement(By.xpath("//input[@id='Login']")).click();
    
    driver.manage().window().maximize();
    
    WebElement contactbtn = driver.findElement(By.xpath("//a[@id='trial-subscribe-now']"));
    contactbtn.click();

    
    
    
    driver.close();
    
    
    
}



public static void WrongUNandPW() throws InterruptedException {
    
    
    driver.get("https://login.salesforce.com/");
    
    driver.findElement(By.xpath("//input[@id='username']")).sendKeys("[email protected]");
    driver.findElement(By.xpath("//input[@id='password']")).sendKeys("lolboy845JJ123");
    
    driver.findElement(By.xpath("//input[@id='rememberUn']")).click();
    driver.findElement(By.xpath("//input[@id='Login']")).click();
    
    
    
    Thread.sleep(2000);
    
    
    
}


}

Any ideas?

1 Answer 1

2

I see a google chrome notification there.

You need to first handle/disable that notification first.

To do that, you can use the following code snippet when initializing a browser

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
.
.
.
ChromeOptions cOptions = new ChromeOptions();
System.setProperty("webdriver.chrome.driver", driverPath);
cOptions.addArguments("--disable-notifications");
WebDriver driver = new ChromeDriver(cOptions);

--disable-notification will help you dismiss those notifications.

If you want to disable infobars, you can use cOptions.addArguments("disable-infobars");

1
  • 1
    will try it out and let you know, thank you @Kenil Fadia Commented Sep 13, 2019 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.