0

I'm able to automate the login process. I would like to automatically click on features within the page AFTER i log in but it looks like the issue is with the login credentials. So it won't automatically click on any fields. The code below is up to that point of automated login. Any suggestions?

I was expecting to be able to automate the clicking of links. At the bottom, I successfully open a new random browser and the close the page and quit the browser**

package stepDefinitions;


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class GreenKartStepDefinition {
    
   public static WebDriver driver;
        
   @Given("User is on ***** login page")
   public static void User_is_on_****_login_page() { 
    
    
    System.setProperty("webdriver.chrome.driver",
                    "C:\\Users\\********\\Downloads\\chromedriver\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--remote-allow-origins=*");
    DesiredCapabilities cp = new DesiredCapabilities();
    cp.setCapability(ChromeOptions.CAPABILITY, options);
    options.merge(cp);
    driver = new ChromeDriver(options);
        driver.manage().window().maximize();
    driver.get("https://*******");
    
    }

    @When("user log in with Shortname {string}")
    public void user_log_in_with(String shortName) throws InterruptedException 
    {
    
    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//*[@id=\"login_user_name\"]")).sendKeys("*******");   
    driver.findElement(By.xpath("//*[@id=\"login_password\"]")).sendKeys("*********");  
    driver.findElement(By.xpath("//*[@id=\"login_contents\"]/fieldset/button")).click();    
     }

    @Then("user is on research cloud home page")
    public void user_is_on_research_cloud_home_page()
    { 
        Properties prop = new Properties();
        try {
            InputStream input = new FileInputStream("C:\\Users\\*******\eclipse-workspace\\***********\\src\\test\\java\\Config\\config.properties");
            prop.load(input);
            
            System.out.println(prop.getProperty("username"));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        driver.get("https://*****.com");

            driver.close();
        driver.quit();
    }
}

1 Answers1

0

You don't need to create any additional instance of DesiredCapabilities to merge them later. You can straight away add the arguments through an instance of Options class as follows:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Carter0615\\Downloads\\chromedriver\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--remote-allow-origins=*");
driver = new ChromeDriver(options);
driver.get("https://www.google.com/");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you! What would be the next line of code that would allow me to click on an element such as "logout" – Carter0615 Mar 17 '23 at 04:03
  • @Carter0615 _to click on an element such as "logout"_: Would depend on the HTML of the website _https://*****.com_ but sounds to be a different question all together. Feel free to ask a new question with your new requirements. – undetected Selenium Mar 17 '23 at 04:07
  • let's say I'm able to automate the process to log into google.com. When I try and click on the elements of the now "supposedly" logged in home page. I can't click on any of the buttons. I think it's a issue with the caching my username and password – Carter0615 Mar 17 '23 at 12:24