My test script are developed using Java with Selenium webdriver api. There is 1 particular scenario where I need to click on a button but I am not able to do that. Following are the test steps and the screenshot for the particular problem.
-Launch OWA(Outlook webapp)
-Create a recurring event in Calendar
-Goto Calendar and click the event
-A popup is displayed with 2 buttons (Screenshot)
-I need to click these buttons
Button Screenshot
I have tried few solutions such as switching frames, handling alert box etc but nothing has helped yet.
How to handle such dialog box.
i tested in my outlook app. it executed well.
please find the coding,
public class testngchecktwo {
static WebDriver driver = new FirefoxDriver();
#Test
public void testa() throws InterruptedException {
driver.get("https://company.com/owa");
driver.manage().window().maximize();
driver.findElement(By.id("username")).sendKeys("me#company.com");
driver.findElement(By.id("password")).sendKeys("pass");
driver.findElement(By.xpath("//input[#value='Sign in']")).click();
Thread.sleep(5000);
//click clanedar icon
driver.findElement(By.xpath("//a[#id='lnkQlCal']/img")).click();
Thread.sleep(5000);
//switch to frame where events listed
driver.switchTo().frame("bLgAAAAA/GWQ3xtO0SIOqswLk6uH4AQDVKQ5oRivJSZbc9pQXHu/BAAAAbHJJAAAC");
//Click Enter to bring up that small popup instead double click in mouse
driver.findElement(By.xpath("//div[#id='divVisualTextContainer']")).sendKeys(Keys.ENTER);
//get hack to orginal window
driver.switchTo().defaultContent();
//click this occurance button
driver.findElement(By.xpath("//button[#id='btn0']")).click();
}
}
Related
In the application i am testing, i am inputting some data in some fields in Chrome Browser with Selenium. I want to click on the "Close" button on the top right of the page, because a notification should appear when i try to do that. However, i cannot find a way to click on that
Is there any way to simulate clicking on the "X" button in the top right of the screen?
I tried to close the browser with driver.close() but that closes the browser immediately. I need to emulate the user action of clicking on the "X" button top right.
Because the X mark is outside the scope of HTML tree structure, you cannot inspect element and get the locator of it. And hence you cannot achieve the action of clicking X using selenium(unless you want to go with driver.close() or driver.quit()). You can try by using either some third party tool or by using java's features like Robot class. Try below code:
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.facebook.com/");
Robot robot = new Robot();
Thread.sleep(2000);
// Press keys Ctrl + W
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_W);
// Release keys Ctrl + W
robot.keyRelease(KeyEvent.VK_W);
robot.keyRelease(KeyEvent.VK_CONTROL);
Try this. Note: Ctrl+W shortcut is to close chrome browser, if you want to close some other browser, use the shortcut accordingly
I'm trying to automate a site but stuck at the point where I need to complete the onboarding process of the user account.
So the problem is I have to add a user and to add the user I have to go through few steps, I have successfully added the user details but when I click on continue button it does not navigates me to the next on same page.
I want to know that how can I navigate to the next step on the same page button by clicking the continue button
Here is my code
public void enter_advisor_details() {
driver.findElement(user_mgmt_opt).click();
driver.findElement(advisor_tab).click();
driver.findElement(add_advisor_btn).click();
driver.findElement(first_name).sendKeys("Test");
driver.findElement(last_name).sendKeys("Automation");
driver.findElement(email).sendKeys("TestAuto#gmail.com");
WebElement element = driver.findElement(By.xpath("//div[#class='mt-8']//button"));
element.click();
}
Note: I have tried Actions class, WebDriverWait and JavaScript executor but nothing works for me
As you can see in the below image the test is getting passed and the button is clicked and the next step does not show up
enter image description here
You are probably missing a delay. Wait for element to become clickable before clicking it, as following:
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[#class='mt-8']//button"))).click();
after logging in with selenium to www.playok.com/en/spades/, the webiste opens a new window which has the same url. but after that, no click on no element works:
System.setProperty("webdriver.firefox.marionette", "some directory");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.playok.com/en/spades/");
driver.findElement(By.cssSelector("button.ckbut.but0")).click();
driver.findElement(By.cssSelector("button.lbpbg.ttup")).click();
WebElement username = driver.findElement(By.cssSelector("input#id"));
username.sendKeys("some username");
WebElement password = driver.findElement(By.name("pw"));
password.sendKeys("some password");
driver.findElement(By.cssSelector("input.bxpad.ttup")).click();//here a new page opens at the same window, which has a start button:
driver.findElement(By.cssSelector("button.lbprm.ttup")).click();//here a new window opens which goes to the main game page and the url is still the same
//but the following click doesnt work; actually no button works, doesnt matter if here a sleep() gets used, click won't work anyway.
driver.findElement(By.cssSelector("button.butsys.minwd")).click();
almost all the buttons were tested; also a sleep() has been used there, but no difference; still no button works.
but there is no other way to access to the website without logging in, and when logging in, this problem accurs.
I want my program to log into indeed.ca (this is working, as long as you enter correct user credentials), navigate to a specific job posting(working), click on the first orange apply button(working), a modal pops up.
Then I want to click on the blue apply button in modal that appears. This is not working. I have commented out my attempt at this portion of the program.
Any help would be much appreciated.
import java.io.IOException;
import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Testing {
public static void main(String[] args) throws IOException {
//enter location of gecko driver
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Padoga\\Documents\\geckodriver-v0.18.0-win64\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
//login works correctly (given that you use proper credentials)
driver.get("https://secure.indeed.com/account/login?service=my&hl=en_CA&co=CA");
driver.findElement(By.xpath("//*[#id=\"signin_email\"]")).sendKeys("abc#gmail.com");
driver.findElement(By.xpath("//*[#id=\"signin_password\"]")).sendKeys("enterPassword");
driver.findElement(By.xpath("//*[#id=\"loginform\"]/button")).click();
//once logged in navigate to specific job
driver.navigate().to("https://ca.indeed.com/cmp/KGHM-International-Ltd./jobs/Financial-Analyst-7a08f1634e7d5c5c");
//clicking on first apply button(orange button) works correctly
Thread.sleep(3000);
driver.findElement(By.xpath("//*[#id=\"apply-state-picker-container\"]/div[1]/span[1]")).click();
//below not working, trying to click on apply button(blue apply button) in popup modal
//I've tried so many different xpaths and ids none seem to be triggering the apply button in modal
Thread.sleep(3000);
driver.switchTo().frame("indeedapply-modal-preload-iframe");
driver.findElement(By.id("apply")).click();
}
}
And here is the various html / javascript? that I have been trying to click on
i.e used as By.id, By.xpath, or By.className, none are working
The below code does not show up when I inspect the page source, only when I inspect the blue apply button in the modal that pops up after clicking the orange apply button, do I see the below code:
<div class="button_outter" id="apply-div">
<div class="button_inner">
<input class="button_content" id="apply" type="submit" name="apply" value="Apply">
</div>
</div>
I have tried using the switch to Iframe, but this is not working in this case. Can you check the below sendkeys approach after clicking the first apply button.
Actions act = new Actions(driver);
act.sendKeys(Keys.TAB, Keys.TAB, Keys.TAB, Keys.TAB, Keys.ENTER);
or
driver.findElement(By.xpath("//body")).sendKeys(Keys.TAB, Keys.TAB,Keys.TAB, Keys.TAB, Keys.ENTER);
Update: It seems, second recommendation actually worked for this case.
Hope this helps. Thanks.
You need to switch to the iframe firtst then call click() method on the Blue Apply button as follows:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(#src,'https://apply.indeed.com/indeedapply/resumeapply')]")));
//perfrom other actions
//finally click on Blue Apply button
driver.findElement(By.xpath("//input[#id='apply']")).click();
It seems the index order of the iframes is backwards, at least that's what it looks like to me. I was able to click the "Blue Apply Button" using the following java code:
driver.get("https://ca.indeed.com/cmp/KGHM-International-Ltd./jobs/Financial-Analyst-7a08f1634e7d5c5c");
wait = new WebDriverWait(driver, 10);
//on my screen I had to scroll down to the orange apply button
WebElement applyButton = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("indeed-apply-button")));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", applyButton);
applyButton.click();
Thread.sleep(1000);
driver.switchTo().frame(1);
driver.switchTo().frame(0);
driver.findElement(By.id("applicant.name")).sendKeys("My First Name is");
driver.findElement(By.id("apply-div")).click();
In my application I am not able to click on a partially visible check box, I even tried to do the same with javascript(scrool and click) and mouse hover actions, could any one find me a solution for the same?
You could try this:
WebElement g_element=g_driver.findElement(g_util.getObject("./ObjectRepository/"+objfile+".xml", objfile, office, "xpath"));
Webdriverwait wait = new Webdriverwait(driver,10)
wait.until(ExpectedConditions.elementToBeClickable(locator);
if(!elementChkBox.isSelected()) {
checkbox.click();
}