0

Any help would be much appreciated.

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), an iframe pops up.

Then I want to click on the blue apply button in iframe that appears. "apply with a different resume?" link (if you are not logged in with indeed you won't see this.)

If you don't have an indeed account, and want to help, just try to click on any link in the pop-up iframe. Example: try to click "Create one now" link

The below code worked 2 weeks ago, but now it seems Indeed.ca made a minor change to site and code is broken

import java.io.IOException;
import java.util.ArrayList;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class Test {
//IOException, InterruptedException, NoSuchElementException 

    public static void main(String[] args) throws IOException, InterruptedException, NoSuchElementException {

        System.setProperty("webdriver.gecko.driver", "C:\\Users\\Padoga\\Documents\\geckodriver-v0.18.0-win64\\geckodriver.exe");

        try {

        FirefoxDriver driver = new FirefoxDriver();

        driver.get("https://secure.indeed.com/account/login?service=my&hl=en_CA&co=CA");
        driver.findElement(By.xpath("//*[@id=\"signin_email\"]")).sendKeys("youremail@email.com");
        driver.findElement(By.xpath("//*[@id=\"signin_password\"]")).sendKeys("password");
        driver.findElement(By.xpath("//*[@id=\"loginform\"]/button")).click();  





        driver.navigate().to("https://ca.indeed.com/viewjob?jk=ff97666702741fef&q=marketing&l=Toronto%2C+ON&tk=1boluh7om5igq9ng&from=web");
//      int size = driver.findElements(By.tagName("iframe")).size();
//      System.out.println(size);
        Thread.sleep(3000);
        //click orange "apply now" button
        driver.findElement(By.xpath("//*[@id=\"apply-state-picker-container\"]/div[1]/span[1]")).click();

        Thread.sleep(3000);

        //don't believe this is working now - below used to switch to correct pop-up iframe
        driver.switchTo().frame(1);
        driver.switchTo().frame(0);

        //not working anymore -- click "apply with a different resume?" link
        driver.findElement(By.xpath("\"//*[@id=\\\"form_container\\\"]/div[2]/div[1]/div[1]/p/a\"")).click();

        //no longer reach below steps
        //click on resume "choose file" button and upload resume
        driver.findElement(By.id("resume")).sendKeys("C:\\Users\\Padoga\\resumes\\Resume.pdf");
        //click blue apply button
        driver.findElement(By.id("apply-div")).click();
        }
        catch(Exception e){
            //System.out.println(e.getMessage());
        }

//      driver.quit();

    }

}
Padoga
  • 495
  • 3
  • 18

2 Answers2

0

You need to switch first to perform any action inside iframe elements

The code to switch to element is :-

driver.switchTo().frame(0);

In above code 0 is a index. so it will swicth control to first iframe present in your DOM. You may need to change the index 1,2,.. so on . There another paramenetrs also to switch to frame without index

Basically, we can switch over the elements in frames using 3 ways.

  • By Index
  • By Name
  • Id By Web Element

Refer below URL for more information

http://toolsqa.com/selenium-webdriver/handling-iframes-using-selenium-webdriver/

https://www.guru99.com/handling-iframes-selenium.html

Hope it will help you :)

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

Try using below code and lets see if it works for you-

driver.switchTo().frame("page_frame");
driver.findElement(By.xpath("//*[@id="form_container"]/div[2]/div[1]/div[1]/p/a")).click();

update-

driver.switchTo().frame("indeedapply-modal-preload-iframe");
driver.findElement(By.xpath("//*[@id="form_container"]/div[2]/div[1]/div[1]/p/a")).click();

update 2-

I found an iframe inside another iframe. So, first you need to switch to the outer iframe then to inner iframe and then to the element.

Possible solutions-

driver.switchTo().frame("indeedapply-modal-preload-iframe");
driver.switchTo().frame(0);
driver.findElement(By.xpath("//*[@id="form_container"]/div[2]/div[1]/div[1]/p/a")).click();

OR

driver.switchTo().frame(0);
driver.switchTo().frame(0);
driver.findElement(By.xpath("//*[@id="form_container"]/div[2]/div[1]/div[1]/p/a")).click();
Kapil
  • 397
  • 4
  • 6
  • error is "No frame element found by name or id page_frame" – Padoga Aug 29 '17 at 06:50
  • What you are getting by running this code- int size = driver.findElements(By.tagName("iframe")).size(); System.out.println(size); – Kapil Aug 29 '17 at 06:52
  • I'm getting 0. Note, my code was working 2 weeks ago, I added int size = driver.findElements(By.tagName("iframe")).size(); System.out.println(size); after code broke, so don't know result when it was working – Padoga Aug 29 '17 at 06:57
  • I tried your updated version, before posting my question, and it doesn't work, tried now still not working. – Padoga Aug 29 '17 at 07:00
  • Minor note to you, you need to put a \ before inner " – Padoga Aug 29 '17 at 07:00
  • driver.findElement(By.xpath("//*[@id=\"form_container\"]/div[2]/div[1]/div[1]/p/a")).click(); – Padoga Aug 29 '17 at 07:00
  • i don't understand why you are getting size 0. '/' is not required. What error you got for my updated answer? – Kapil Aug 29 '17 at 08:14