How to Automate new Facebook Sign up popup? - java

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

Related

How to check remember_me checkbox of Jenkins login page using selenium?

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']

Can not take correct identifier of WebElement (Sign in at iCloud.com)

I have trouble identifying 'sign in with Apple ID' element (at iclod.com page).
This is what I'm using now:
WebElement username = driver.findElement(By.xpath("//[#id=\"account_name_text_field\"]");
username.sendKeys("my_email#icloud.com");
Also, I tried to use CSS created by Chropath and Ranorex, still not working.
What I'm doing wrong?
Path to needed Element
Please check below solution. Iframe is associated with your web page and you need to switch to iframe before you interact with web element input box.
driver = webdriver.Chrome(executable_path=r" path of chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("https://www.icloud.com")
wait.until(EC.presence_of_element_located((By.ID, "auth-frame")))
driver.switch_to.frame("auth-frame")
inputBox = wait.until(EC.element_to_be_clickable((By.ID, "account_name_text_field")))
inputBox.send_keys("your test")
# switch back to main window
driver.switch_to.default_content()
output:
The element is inside the iframe, you need switch first.
You can use .frameToBeAvailableAndSwitchToIt:
driver.get("https://www.icloud.com/");
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("auth-frame")));
WebElement username = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("account_name_text_field")));
username.sendKeys("my_email#icloud.com");
Add WebDriverWait, the web loading is rather long.
Iframes can be tricky. You have to change focus to the frame before accessing that text box.
Use switchTo().frame ();
It can take the following parameters :
switchTo().frame(int frame number): Defining the frame index number,
the Driver will switch to that specific frame
switchTo().frame(string
frameNameOrId): Defining the frame element or Id, the Driver will
switch to that specific frame
switchTo().frame(WebElement
frameElement): Defining the frame web element, the Driver will
switch to that specific frame
WebDriver driver = new FirefoxDriver();
waitdriver = new WebDriverWait(driver , 10);
driver.get("https://www.icloud.com/");
driver.switchTo().frame("auth-frame");
waitdriver.until(ExpectedConditions.presenceOfElementLocated( By.xpath("//*[#id=\"account_name_text_field\"]")));
WebElement textbox=driver.findElement(By.xpath("//*[#id=\"account_name_text_field\"]"));
textbox.click();
textbox.sendKeys("HelloWorld#gmail.com");
1) The xpath pattern which you have written is wrong.
2) You can always verify the xpath or cssSelector in ChroPath before using it in your script.
3) If the element is inside iframe then you must have got the iframe xpath as well as the element xpath in ChroPath. Please use them.
Please follow this video tutorial to make the best use of this iframe feature of ChroPath.

Unable to find draggable web element in selenium webdriver(while other user is able to do so with same code)

I'm trying to test drag and drop functionality using selenium webdriver while writing test scripts using java in eclipse.I'm unable to find the web element that I want to drag while my other friend is able to find the element with same code.
Below is the code we both have used.
WebElement draggable = driver.findElement(By.id("draggable"));
I'm using site www.way2automation.com/demo.html and the page i'm trying to find webelement on, is http://way2automation.com/way2auto_jquery/draggable.php
Please suggest something to find the webelement.
Try this below code, using Action Class.
WebElement from = driver.findElement(By.id("drag"));
WebElement to = driver.findElement(By.id("drop"));
Actions act = new Actions(driver);
act.clickAndHold(from).build().perform();
Thread.sleep(3000);
act.clickAndHold(to).moveToElement(to).release(to).build().perform();
Thread.sleep(2000);
WebElements were not being identified even with right locators because these webElements were under an iFrame so First we need to switch to the iFrame before performing drag and drop. And then we also need to check for the availability of SourceElement and DestinationElements. Below code is working fine for this problem.
//Wait for the frame to be available and switch to it
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector(".demo-frame")));
WebElement Sourcelocator = driver.findElement(By.cssSelector(".ui-draggable"));
WebElement Destinationlocator = driver.findElement(By.cssSelector(".ui-droppable"));
builder.dragAndDrop(Sourcelocator,Destinationlocator).build().perform();
String actualText=driver.findElement(By.cssSelector("#droppable>p")).getText();
Assert.assertEquals(actualText, "Dropped!");

With Selenium WebDriver unable to switch to a popup

A pop will display asking to enter contact info. It is not an iframe, or alert or windows based popup. The URL does not even change. On the main homepage I click on 'Contact Us' and I get a pop up, looks like a form. How do I switch driver control to it and send input contact info??
Any help is alway highly appreciated.
I am not sure if you have a specific problem, or it's just synchronization issue (which this example would address):
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, 10); // used for synchronization
driver.get("http://uptake.com/");
// Make sure page was loaded
WebElement contactUs = wait.until(
ExpectedConditions.elementToBeClickable(By.linkText("Contact Us")));
contactUs.click();
// Wait for Contact Us div to become visible
// (by checking that title is displayed)
wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath("//h2[contains(text(), 'Contact us below.')]")));
// Start filling form
driver.findElement(By.name("name")).sendKeys("John Smith");
// ... rest of the fields
driver.findElement(By.name("message")).sendKeys("Hello!");
driver.findElement(By.xpath("//input[#value='Send']")).click();

Not able to locate element in Selenium tried xpath,name,id,css selector

I have tried using the name, id, xpath. However I get the same error in Eclipse that it is not able to locate the element.
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://accenturenordicspov.service-now.com/navpage.do");
driver.findElement(By.xpath("/html/body/form/table/tbody/tr[3]/td[2]/input")).sendKeys("John");
driver.findElement(By.xpath("/html/body/form/table/tbody/tr[4]/td[2]/input[1]")).sendKeys("A***");
driver.findElement(By.id("/html/body/form/table/tbody/tr[7]/td[2]/button")).click();
According to the link you've given, the form is in an iframe. Hence, you need to switch to the frame and then fill the form. You should try this:
driver.switch_to.frame("gsft_main")
driver.findElement(By.xpath("//input[#id='user_name']").sendKeys("John");
driver.findElement(By.xpath("//input[#id='user_password']").sendKeys("A***");
driver.findElement(By.xpath("//button[#id='sysverb_login']").click();
May be in different frame. Kindly check for the frame or iframe tag is parent of the box you are going to interact.
If yeas then You have to switch to that frame then only You can interact.
It first needs to move to that frame and then input the elements. Above code will work if just put this piece of code before inputting the elements:
String x="gsft_main";
driver.switchTo().frame(x);

Categories