I am writing selenium script for Gmail login and logout functionality. I am able to successfully login using below code.
//Open gmail
driver.get("http://www.gmail.com");
// Enter userd id
WebElement element = driver.findElement(By.id("Email"));
element.sendKeys("xyz#gmail.com");
//wait 5 secs for userid to be entered
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//Enter Password
WebElement element1 = driver.findElement(By.id("Passwd"));
element1.sendKeys("Password");
//Submit button
element.submit();
But i could not write a script to logout. Could yu please provide me script for logout?
Thanks!
It is a very bad idea trying to automate Gmail. First of all, it is against Google's policy and when you sign up for Gmail, you accepted terms and conditions that you won't automate. Having said that there are many efficient ways to connect to your Gmail account. One of the approaches is to use IMAP client like IMAP4. Using this, you can connect to your Gmail, go through your inbox, delete messages,sign out etc. By doing this, you don't have to worry about automating UI portion. Also, Google changes its UI frequently just to stop people from automating it, so if you automate Gmail UI, then it might work today but it won't work after a couple of days.
Go through this link and you should be able to implement IMAP4 in your tests within few minutes:
http://mailsystem.codeplex.com/discussions/269058
Try the below code.
driver.findElement(By.className("gb_Ta")).click(); // To click the flyout menu
driver.findElement(By.className("gb_71")).click(); // To click the sign out button
Try the code below
driver.findElement(By.xpath("//*[#id='gb']/div[1]/div[1]/div/div[3]/div[1]/a")).click();
// click on actual logout button step 2
driver.findElement(By.id("gb_71")).click();
//closing the webdriver window after successful completion of the test
driver.close();
WebDriverWait wait=new WebDriverWait(driver,50);
WebElement logout=driver.findElement(By.cssSelector("span.gb_4.gbii"));
logout.click();
WebElement signout=driver.findElement(By.id("gb_71"));
signout.click();
After login to gmail, Try this code to logout:-
driver.findElement(By.xpath("//span[#class='gb_7 gbii']")).click(); driver.findElement(By.id("gb_71")).click();
use xpath
// Click on the image icon present in the top right navigational Bar
driver.findElement(By.xpath("//div[#class='gb_1 gb_3a gb_nc gb_e']/div/a")).click();
//Click on 'Logout' Button
driver.findElement(By.xpath("//*[#id='gb_71']")).click();
//Close the browser.
driver.close();
use cssSelector
//Click on the profile image present in the right top corner
driver.findElement(By.cssSelector("span.gb_3a.gbii")).click();
//Click on 'Sign Out' button
driver.findElement(By.id("gb_71")).click(); //Close the browser
window driver.close();
use cssselector:
driver.findElement(By.cssSelector("span.gb_8a.gbii")).click();
driver.findElement(By.id("gb_71")).click();
Try this code for sign out the gmail using the selenium webdriver. It's working for me
driver.findElement(By.cssSelector(".gb_b.gb_db.gb_R")).click();
Thread.sleep(5000);// Click on the image icon present in the top
right navigational Bar
driver.findElement(By.cssSelector(".gb_Fa.gb_Pe.gb_We.gb_wb")).click();
Thread.sleep(5000); //Signout button
Related
I cannot check-in the user credentials encrypt/decrypt logic, to the git, so for now we are copying the class files on CI machines. But it has dependency to contact IT team for copy access.
Approach I am thinking is like - create a customer chrome profile, launch it using selenium chrome driver, on Jenkins login page, add user name, password and click remember me. I hope this setting will persisted to next chrome session as well. But, somehow the code is not able check the checkbox. It do identify it but no click.
I have tried by suing wait, maximize the window, still get the error as :
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable at point (764, 504). Other element would receive the click: ...
Code I am using :
driver.get(input_params.get("JenkinsURL"));
driver.manage().window().maximize();
WebElement remember_me = driver.findElement(By.xpath("//*[#id='remember_me']"));
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
remember_me.click();
Please try with the below. It worked for me.
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().setScriptTimeout(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("URL");
WebElement checkbox = driver.findElement(By.xpath("/html/body/div/div/form/div[4]/label/div[1]"));
checkbox.click();
Please use the xpath as below:
//div[#class='Checkbox-indicator']//*[local-name(0='svg']
I've tried to Automate Facebook Signup page (new version consists of a popup). I've tried to switch to iframe but I've failed to find it.
Please help me. Please share the code.
The code below worked for me. Signup section is not any new pop-up window or frame. So don't need to switch to any frame or window. Just locate the fields and enter the required data using methods like sendKeys, clicks etc.
WebDriver Driver = new ChromeDriver();
Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//Driver.manage().window().maximize();
String url = "https://www.facebook.com/";
Driver.get(url);
WebElement createAcount=Driver.findElement(By.id("u_0_2"));
createAcount.click();
WebElement firstname=Driver.findElement(By.id("u_1_b"));
firstname.sendKeys("Tina");
WebElement surname=Driver.findElement(By.id("u_1_d"));
surname.sendKeys("Roy");
I think Sign-up input fields are NOT in the iframe, so you don't need to switch.
Just doing this test. The elements are dynamically generated so they have different values everytime. Group the element selection by more attributes
I have a scenario - when I click a button(abcB) on my test url(http://example.com), it will be redirected to different url(http://yourname.xyz) and there when I click a button(xyzB), it will come back to my usual test url(http://example.com) and does performs further function. Please let me know how I could do this Selenium Webdriver.
It is a simple and straight forward task. I am writing some pseudo code, because you didn't share any html code for reference. please use the below code and try.
driver.findElement(By.Xpath("<your xpath reference of button in first page>").click(); //to click on the button, and will navigate to target page
driver.getTitle();// to get the title to ensure you are in the correct page
driver.findElement(By.Xpath("<your xpath reference of button in second page>").click();
driver.getTitle();// to get the title to ensure that the browser is navigated back
If I understand not wrong you scenario is like this
driver.findElement(By.Xpath("Your xpath").click();
//wait for few second for loading site
for (String windows : wd.getWindowHandles()) {
wd.switchTo().window(windows);
if (wd.getCurrentUrl().startsWith(Link + "xyz.com")) {
//Your Operation
}
if (wd.getCurrentUrl().startsWith(Link+"yzx.com")) {
//Your Operation
}
}
Here What I did, I click on redirect link.And wait for few second for site load.After redirection, i return desire tab link start with, where you can give other condition also!!
Hope it will help you
First click on the second URL locator match the title and come back to first URL do the same thing here by this you can handle redirected URL
You can try this sample example
WebDriver driver=new FirefoxDriver();
//Go to first URL and click on Download menu
driver.get("http://www.seleniumhq.org");
driver.findElement(By.xpath("//*[#id='menu_download']")).click();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//Click on the Source code to redirect to second URL
WebElement sourceCode=driver.findElement(By.xpath(".//*[#id='mainContent']/p[1]/a[2]"));
sourceCode.click();
//Get the title of SecondURL and match
String SecondUrl= driver.getTitle();
if(SecondUrl.contains("GitHub - SeleniumHQ/selenium: A browser automation framework and ecosystem."))
{
System.out.println("welcome to second URL");
}
//come back to First URL by click on link
driver.findElement(By.xpath("//a[contains(text(),'http://seleniumhq.org')]")).click();
//Get the title of FirstURL and match
String FirstUrl= driver.getTitle();;
if(FirstUrl.contains("Selenium - Web Browser Automation"))
{
System.out.println("welcome to First URL");
}
how to retrieve response text generated in browser after executing script in selenium web drive.in the above figure the underlined response I want to retrieve and store it in a string.
//Opening the web page
driver = new ChromeDriver();
System.setProperty("webdriver.chrome.driver", "/usr/local/share/chromedriver");
driver.get(Mymark.str);
//Opening the login page
WebElement login= driver.findElement
(By.xpath("//a[text()='Log in']"));
login.click();
// Enter Username
WebElement Usrnm=driver.findElement
(By.xpath("//div[#id='mainContainer']//mymark-login[#class='x-scope mymark-login-0']//input[#name='uname']"));
Usrnm.sendKeys("nayazjh");
//Enter Password
WebElement Pswd= driver.findElement
(By.xpath("//div[#class='content']//div[#class='loginlayout layout vertical justified style-scope mymark-login']//input[#name='password']"));
Pswd.sendKeys("doordie");
//click on remember me button
driver.findElement(By.xpath( "//div[#id='toggleButton']")).click();
//Click on login button
WebElement logIn= driver.findElement
(By.xpath("//div[#class='lsubmitarea style-scope mymark-login']//paper-button[text()='Log in']"));
logIn.click();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement
(By.xpath("//paper-button[text()='Add Bookmark Group ']")).click();
driver.findElement
(By.xpath("//paper-dialog[#id='addgroupdialog']//input[#id='input']")).sendKeys("selenium71");
element = driver.findElement
(By.xpath("//paper-dialog[#id='addgroupdialog']//div[#class='adddialogsubmit style-scope mymark-addgroup']" +
"//paper-button[#id='addgroupbutton']"));
element.click();
here i need a code to retrieve the response in java
}
1
The above image shows the response I want to get it using selenium or java
how to retrieve response text generated in browser after executing script in selenium web drive.in the above figure the underlined response I want to retrieve and store it in a string.
As far as I know it is impossible for selenium to get the actual response.
Selenium is build "on top". It can not directly control how the browser interacts with the server nor is it supposed to support this kind of control.
Selenium is thought as an ui automation framework, i.e. clicking and asserting ui state. It is not meant to intercept browser-server communication.
I am new to selenium Java(Eclipse). I am automating OLX Site ad post for my learning when I go to add post page at Link: http://www.olx.com.pk/posting/. On this page when I click category drop down a window appears I am unable to get elements on that window. Important: It is not a new window fancy div is used for it pic is attached enter image description here
I am able to access the fancy box and the contents. Please check the below code:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.olx.com.pk/posting/");
Thread.sleep(10000);
driver.findElement(By.xpath("//div[#id='category-breadcrumb-container']")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//div[#id='fancybox-content']//a[#alt='Mobiles']")).click();