Selenium "Cannot login" - selenium-webdriver

I am unable to access through this lock icon and get to login. I have used different locator options.
The current code I am using:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("example.com");
driver.manage().window().maximize();
driver.findElement(By.id("login-trigger")).click();
driver.findElement(By.id("username")).sendKeys("User1");
driver.findElement(By.id("password")).sendKeys("123456");
driver.findElement(By.id("submit")).click();

Instead of writing driver.findElement(By.id("submit")).click();
try this : driver.findElement(By.id("submit")).sendKeys(Keys.ENTER);

Related

Selenium PDF Parser

In my application I will land in one page there will be a text in there and I have to open a PDF in the same page and compare the text in the PDF and the main page matches.
I am using pdfbox -1.8.15
But when I run the below code getting this exception:
Exception in thread "main" java.io.IOException:
Error: End-of-File, expected line at
org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1523) at
org.apache.pdfbox.pdfparser.PDFParser.parseHeader(PDFParser.java:372) at
org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:186) at
TestCases.lastpdf.main(lastpdf.java:83)
driver.findElement(By.xpath("//*[#id=\"ctl00_cph_main_rg_QiSummaries_ctl00__0\"]/td[2]/img")).click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
String winHandleBefore = driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles()){
//Switch to child window
driver.switchTo().window(winHandle);
}
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
URL url = new URL(driver.getCurrentUrl());
System.out.println(url);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
String mypdftxt;
BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
PDFParser parser = new PDFParser(fileToParse);
parser.parse(); // exception occurs here
mypdftxt = new PDFTextStripper().getText(parser.getPDDocument());
System.out.println(mypdftxt);

Files not found error when tried to upload files using AutoIT and Selenium

When I am trying to run the AutoIT.exe script or my Selenium script, it is throwing 'File Not found error'. Please suggest!
Selenium code snippet: ===================================
public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", "C:\\Users\\IBM_ADMIN\\Desktop\\Drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://demo.automationtesting.in/Register.html");
driver.manage().window().maximize(); Thread.sleep(2000);
driver.findElement(By.xpath("//input[#id='imagesrc' and #type='file']")).click();
Runtime.getRuntime().exec("C:\\Users\\IBM_ADMIN\\Desktop\\Selenium practise\\SeleniumAssignment\\AutoIT\\MultipleFileUpload.exe"+" "+"C:\\Users\\IBM_ADMIN\\Desktop\\0234_005.pdf"); Thread.sleep(2000);
driver.findElement(By.xpath("//input[#id='imagesrc' and #type='file']")).click();
Runtime.getRuntime().exec("C:\\Users\\IBM_ADMIN\\Desktop\\Selenium practise\\SeleniumAssignment\\AutoIT\\MultipleFileUpload.exe"+" "+"C:\\Users\\IBM_ADMIN\\Desktop\\BRP_SujataChakraborty.pdf"); driver.quit(); }
AutoIt Code Snippet: ============================
ControlFocus("Open","","Edit1")
ControlSetText("Open","","Edit1",$CmdLine[0])
ControlSetText("Open","","Edit1",$CmdLine[1])
ControlSetText("Open","","Edit1",$CmdLine[2])
ControlClick("Open","","Button1")
Is brower file dialog active window? If not auto it script will enter value in window whichever is active. Do make sure file dialog active?. Do interact with brower once it is started. And one more thing if you input type is file then you can use send keys instead of auto it to enter value.

Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity"

Selenium Webdriver runtime Exception: unexpected alert "Please close other open tabs of the application and re-open this activity", even though there are no other tabs open.
The Automation scripts were working fine, but recently I am getting the above exception.The Screenshot of the Alert:
I tried with different versions of chrome, selenium stand alone driver, but the issue still exist. Why is this alert coming, even though the application is not open in any of the tabs or browsers other than the one execution through online?
If this pop up is coming at some specific location every time then you can simply accept it by writing below lines :
WebDriver wb=new ChromeDriver();
wb.switchTo().alert().accept();
Else if any unexpected pop up is coming ,while initializing the driver then you can use the below code :
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
String path=new GetBasePath().getPath_XML()+dir;
prefs.put("download.default_directory", path);
options.addArguments("disable-extensions");
prefs.put("credentials_enable_service", false);
prefs.put("password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);
options.addArguments("chrome.switches","--disable-extensions");
options.addArguments("--test-type");
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
System.setProperty("webdriver.chrome.driver",**path to chromedriver.exe**"));
WebDriver wb= new ChromeDriver(cap);
My personal opinion , use both.

Error when trying to login using selenium webdriver in IE11

I am getting the below error when i try to login and select a drop down in login page using selenium webdriver in IE11.
[{
DesiredCapabilities capabilities=DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("webdriver.ie.driver", "C://Users//chetana.inamdar//Desktop//selenium//IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(capabilities);
driver.navigate().to("url");
driver.findElement(By.id("ctl00_plhContent_txtUserName")).sendKeys("username");
driver.findElement(By.id("ctl00_plhContent_txtPassword")).sendKeys("Password");
driver.findElement(By.id("ctl00_plhContent_btnLogin")).click();
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
//Select dropdown=new Select(driver.findElement(By.xpath(".//*[#name='ctl00$plhContent$Tabs$pnltabPermanentArea$ddlIDSearch']")));
Select dropdown=new Select(driver.findElement(By.name("ctl00$plhContent$Tabs$pnltabPermanentArea$ddlIDSearch")));
dropdown.selectByValue("CS Number");
System.out.println("the output of selected is"+driver.findElement(By.id("ctl00_plhContent_Tabs_pnltabPermanentArea_ddlIDSearch")).isSelected());
driver.findElement(By.id("ctl00_plhContent_Tabs_pnltabPermanentArea_txtIDSearch")).sendKeys("1234");
}]
Error:

PhantomJSDriver- How to initialize the driver?

Can someone tell me how I begin to test with PhantomJS? I have downloaded the PhantomJS exe file and also set my "path" variable.
And I do something similar for chrome like
if(config.getProperty("browser").equals("chrome"))
{
System.setProperty("webdriver.chrome.driver", "C:drivers\\chromedriver.exe");
driver= new ChromeDriver();
}
which is
if(config.getProperty("browser").equals("phantom"))
{
System.setProperty("webdriver.chrome.driver", "C:\\drivers\\chromedriver.exe");
driver= new PhantomJSDriver();
}
But, this does not work. Please help. I do not want to use RemoteWebDriver or GhostDriver
I figured it out:
if(config.getProperty("browser").equals("phantom"))
{
System.setProperty("phantomjs.binary.path", "C:\\drivers\\chromedriver.exe");
driver= new PhantomJSDriver();
}
PhantomJSDriver accepts path to executable as a constructor argument:
if (config.getProperty("browser").equals("phantom"))
driver= new PhantomJSDriver("C:\\drivers\\chromedriver.exe");
Find the phantomjs code below and set the property key and value:
//System.setProperty("phantomjs.binary.path","phantomjs.exe path");
System.setProperty("phantomjs.binary.path", System.getProperty("user.dir")+"/ExternalLibraryFiles/phantomjs-2.1.1-windows/phantomjs-2.1.1-windows/bin/phantomjs.exe");
driver =new PhantomJSDriver();

Resources