0

I am trying to press the find jobs button on the home page of indeed using selenium. I have used By.id, By.xpath and By.className but it is still not working. There are a lot of similar questions to the one I am asking but I already tried them and they aren't different from what I have already done. I am using the Opera browser (don't want to use others) if that matters and the version is 3.4.0.

There is no error shown after execution.

Again the question is how do I click the button using selenium and java on an opera browser?

Appreciate the help.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.opera.OperaDriver;
import org.openqa.selenium.opera.OperaOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class SeleniumLearning 
{
    WebDriver driverC;  
    WebDriver driverO;

public static void main(String[] args) throws InterruptedException
{
    SeleniumLearning SL = new SeleniumLearning();
    //SL.invokeOperaBrowser();
    SL.indeedOpera();
    //SL.yahooOpera();
    //SL.duckduckgoOpera();
}
public void indeedOpera() throws InterruptedException
{
    System.setProperty("webdriver.opera.driver", "C:\\Program Files (x86)\\Selenium Stuff\\operadriver_win64\\operadriver.exe");
    driverO = new OperaDriver();
    //driverO.manage().deleteAllCookies();
    driverO.manage().window().maximize();
    driverO.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driverO.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

    driverO.get("http://www.indeed.com");
    driverO.findElement(By.className("input_text")).sendKeys("HR");

    //Trying different methods
    //These don't work individually either
    Thread.sleep(3000);
    driverO.findElement(By.id("fj")).click();
    Thread.sleep(3000);
    driverO.findElement(By.xpath("//*[@id='fj']")).click();
    Thread.sleep(3000);
    driverO.findElement(By.className("inwrapBorderTop")).click();
}
}
8
  • have you used javascript click? did you try to click on parent element or child element and see what happens ? Commented May 5, 2017 at 12:07
  • I have zero clue how to implement any of that. Commented May 5, 2017 at 12:46
  • And yet you are saying that you searched to forum for similar questions. please search again. Commented May 5, 2017 at 12:47
  • 1
    what is the error that you see? Commented May 5, 2017 at 13:26
  • For Kushal: There is no error it simply doesn't click the button. It executes this driverO.findElement(By.className("input_text")).sendKeys("HR"); perfectly. Then I think it executes it but website doesn't recognize it? (Not sure how selenium works behind the scenes.) Commented May 5, 2017 at 14:31

2 Answers 2

1

Try JS code to click the element as below: driver.get("http://www.indeed.com"); driver.findElement(By.className("input_text")).sendKeys("HR");

Thread.sleep(1000);

WebElement buttontoclick=driver.findElement(By.id("fj"));

((JavascriptExecutor) driver).executeScript("arguments[0].click();", buttontoclick);
Sign up to request clarification or add additional context in comments.

Comments

0

When I looked at the site directly, I manually performed the test first. I entered "hr" and then clicked the button. At that time, the button was accessible via XPath //*[@id="fj"]

I then tried to go back a second time to see if the locator for the button only became enabled if there was search text, and I immediately noticed that the screen layout no longer looks the same. I imagine if I cleared my cookies it would but I also noticed that upon second try, it already had my previous text in the textbox, but the locator for the button was not shown, only the division with XPath //*[@id="jobsearchform"]/div[5]/input

I don't know if this second locator will work with the first-time load of the web page or not, but it's likely it should work in either case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.