如何单击按钮立即申请

时间:2020-02-01 12:46:39

标签: java selenium selenium-webdriver

enter image description here

HTML:

<a href="https://stgtest.flexforceondemand.com/associateregistration/consenttoproceed?bid=U20xNFozbFBkV0pFZWpWWlpGRjRVMUZJZUVwWFFUMDlPanBnTHhJRmY4R1VRWVh6aFVHN2swcW0%2A&amp;zc=VkdSdVVGZHRTbEZVY3pkWFRYZGFkRTVTUVhFclp6MDlPanJFTUVSazZNV0ErYTdlZ0ovR1BhWng%2A" class="btn btn-success btn-lg">Apply Now</a>

我已经尝试了以下方法:

driver.findElement(By.xpath("//a[text()='Apply Now']")).click();
driver.findElement(By.xpath("(.//[@href='Apply Now'])")).click();
driver.findElement(By.xpath("//a[@href='Apply Now']")).click();
driver.findElement(By.linkText("Apply Now")).click();
driver.findElement(By.className("Apply Now")).click(); 
driver.findElement(By.xpath("//div[contains(@class,'btn btn-success btn-lg')]")).click();
driver.findElement(By.xpath("//div[contains(@class,'btn btn-success btn-lg')]")).click();v

4 个答案:

答案 0 :(得分:1)

尝试使用webdriver单击,直到元素正确装入Dom并准备接收click

WebDriverWait wait = new WebDriverWait(driver, 40);

wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[.='Apply Now']"))).click();

答案 1 :(得分:0)

选项1 试试By.CssSelector 选项2 不确定是否要在单击元素之前检查元素是否存在。如果不存在,请使用wait.until。 如果可能,粘贴错误,您将到达此处。 希望这会有所帮助。

答案 2 :(得分:0)

所需元素是动态元素,因此要定位regressor = Sequential() regressor.add(LSTM(units = 100, return_sequences = True, input_shape = (x_train.shape[1], 5))) regressor.add(Dropout(0.25)) regressor.add(LSTM(units = 2, return_sequences = True)) regressor.add(Dropout(0.25)) regressor.add(LSTM(units = 2, return_sequences = True)) regressor.add(Dropout(0.25)) regressor.add(LSTM(units = 2)) regressor.add(Dropout(0.25)) regressor.add(Dense(units = 2)) 并将其放置在click()上,您需要为elementToBeClickable()引入 WebDriverWait ,并且可以使用以下任一{ {3}}:

  • linkText

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("Apply Now"))).click();
    
  • cssSelector

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.btn.btn-success.btn-lg[href*='associateregistration']"))).click();
    
  • xpath

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='btn btn-success btn-lg' and contains(@href, 'associateregistration')][text()='Apply Now']"))).click();
    

答案 3 :(得分:0)

请尝试此操作,也许会有所帮助

driver.findElement(By.id("select2-section-tn-container")).click();