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();
Related
i have the follow problem:
I have a button inside a form (the web page have a login and password text box and a button), this button calls a js funtion and after the login and password validation, calls the main web page. The html code is this (this code is inside of a form calls "login" and method = POST):
<INPUT class="btn btn-mini btn-primary" onclick=submitForm(); type=button value="Sign On">
In Selenium i try with the follow statements, but without success:
driver.findElement(By.xpath("//input[#type='button']")).click();
driver.findElement(By.cssSelector("input[type='button'][#value='Sign On']")).click();
driver.findElement(By.xpath("//input[#value='Sign On']")).click();
when i run the script, login and password text are filled correctly, but the click in the button it's no working.
Could you help me with this?
Thanks!
Gonzalo from Chile
To click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.btn.btn-mini.btn-primary[value='Sign On'][onclick^='submitForm']"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[#class='btn btn-mini btn-primary' and #value='Sign On'][starts-with(#onclick, 'submitForm')]"))).click();
i found the solution, reading a lots of issues related with this. I'm working with win 10 and IE 11, so, Selenium has a problem with this, because need the size of the text, apps, and others items in 100%. In my case, i had this configuration in 150%. Fixing this, i run the script one again and it works.
The code used is:
WebElement button = null;
List<WebElement> inputs = webDriver.findElements(By.tagName("input"));
for (WebElement input : inputs) {
if (input.getAttribute("value").equals("Log In")) {
button = input;
break;
}
}
if (button == null) {
System.err.println("Cannot find button!");
} else {
System.out.println("Clicking button now!");
button.click();
}
After this, i check another code more efficient:
driver.findElement(By.cssSelector("input[type='button'][value='Sign On']")).click();
This works too.
thanks all off you for your help
I tested first if the first line of code to click the XPath which works but then when I add a second line of code to click By.name() it doesn't work, so I tried to change in XPath and then in CSS selectors but it only clicks the first one the (XPath code of line). I have tried but it doesn't seem to click the two other elements.
What I found out was that it only clicking what was on the first page, didn't really matter what was on the new page and I told to click on an element that I wanted to do. I'm using the Selenium version 3.141.59.
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\ae65255\\Desktop\\java_gui\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://shop.palaceskateboards.com/collections/new");
driver.findElement(By.xpath("//*[#id=\"product-loop\"]/div[#data-alpha='S-LINE JOGGER BLACK']")).click(); //only this one work
driver.findElement(By.name("button")).click(); //second click dosen't work?
driver.findElement(By.linkText("Cart")).click(); //this dosen't work too?
}
Add some wait to let the page load before locating the element
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.name("button")));
button.click();
The third locator By.linkText("Cart") didn't work because the button doesn't have Cart text, it's in the data-text and value attributes.
As a side note, you should use By.partialLinkText() when looking for partial text.
I am having an issue in regards to a md-dialog pop-up in an angularJS app that I am unable to click in selenium. When i click a button the dialog box appears and becomes the active element on the screen, darkening the background. I have tried switchTo with active element, frame, alert and none of these seem to work. My most recent attempt was trying to swap windows using the below code:
winHandleBefore = driver.getWindowHandle();
Set<String> numOfWindows = driver.getWindowHandles();
System.out.print(numOfWindows.size());
for(String winhandle : driver.getWindowHandles())
{
driver.switchTo().window(winhandle);
report.updateTestLog("Switched to window", "", Status.PASS);
}
the S.o.p for the size is always outputted as 1. There is a wait in after the initial button is clicked before the popup appears to assure it has the proper time to appear. Not sure what else there is to do, I have been scouring the internet for an answer and I haven't come across anything that will let me click the elements in that popup
Edit: This is the html for the md-dialog
<md-dialog class="quote _md md-transition-in" aria-label="Summary" role="dialog" tabindex="-1" id="dialogContent_78" aria-describedby="dialogContent_78" style="">
Edit 2: Forgot to say, I am trying to click a button inside the md-dialog popup
Edit 3: After reviewing the code a bit more I noticed that the md-dialog popup has a container div that is taking up the entire screen and that it is also calling in html from another file. The container div html:<div class="md-dialog-container ng-scope" tabindex="-1" style="top: 972px; height: 769px;">
In case someone has same issue the pop-up was registering as hidden even though it had appeared on screen, so any attempt to click a button was futile as the button was seen as hidden. The workaround was to find the button using the findElement() method, assign it to a variable and then use a javascriptExectutor to click it even though it was hidden. This is not ideal if you are trying to reproduce user input but it is a workaround. Code is below.
WebElement hiddenButton = driver.findElement(uniqueIdentifier);
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", hiddenButton);
report.updateTestLog(flowName, uniqueIdentifier + " Hidden Button Pressed", Status.DONE);
Hope this helps anyone who finds it.
I am using Selenium to automate the checkout process of a website and can not figure out how to select this certain element properly. So far I have tried all of the following with no luck:
//no such element
driver.findElement(By.id("Something here")).click();
//no such element
driver.findElement(By.xpath("//*[#id="add-remove-buttons"]/input")).click();
//no such element
driver.findElement(By.name("commit")).click();
It seems like the closest I've gotten is with:
driver.findElement(By.className("button")).click();
Using this gives me an error saying the button is not visible. So it looks like I'm heading in the right direction with this, but I'm not sure where to go from here. Here is the HTML source of the button:
<input type="submit" name="commit" value="add to cart" class="button">
not sure if this plays a part in it but when this button is clicked it changes into a new button. The same location, but different color, text, and functionality.
If you wanted to take a look for yourself here is the website:
http://www.supremenewyork.com/shop/accessories/yf89tm27c/e8c56njah?alt=0
and the button I am trying to click is the add to cart button.
Try the following code:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.name("commit")));
button.click();
Hope it helps you!
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();
}
}