我希望我的程序登录到really.ca(只要你输入正确的用户凭证,这是有效的),导航到特定的职位发布(工作),点击第一个橙色申请按钮(工作),莫代尔弹出。
然后我想点击出现的模态中的蓝色应用按钮。这不起作用。我已经评论了我对该计划这一部分的尝试。
非常感谢任何帮助。
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();
}
}
这是各种html / javascript?我一直试图点击 即用作By.id,By.xpath或By.className,都不起作用 当我检查页面源时,下面的代码没有显示,只有当我检查单击橙色应用按钮后弹出的模式中的蓝色应用按钮时,我是否看到以下代码:
<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>
答案 0 :(得分:1)
我尝试过使用iframe切换,但在这种情况下这不起作用。单击第一个应用按钮后,您可以检查以下sendkeys方法。
Actions act = new Actions(driver);
act.sendKeys(Keys.TAB, Keys.TAB, Keys.TAB, Keys.TAB, Keys.ENTER);
或
driver.findElement(By.xpath("//body")).sendKeys(Keys.TAB, Keys.TAB,Keys.TAB, Keys.TAB, Keys.ENTER);
更新:看来,第二项建议实际上适用于此案例。
希望这会有所帮助。感谢。
答案 1 :(得分:1)
您需要切换到iframe
firtst,然后按 click()
应用按钮调用Blue
方法,如下所示:
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();
答案 2 :(得分:1)
似乎iframe的索引顺序是倒退的,至少对我来说是这样的。我能够点击&#34;蓝色应用按钮&#34;使用以下java代码:
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();