2017-08-25 124 views
0

下面的代碼是點擊保存按鈕,但它不工作&即使錯誤也不顯示,我也有共享的DOM,請幫助我已經嘗試過classname,xpath,csslocator ,JavaScript向下滾動,操作類,但仍然不適合我,請幫助。無法點擊保存按鈕爲naukri.com

WebElement element = driver.findElement(By.xpath(".//*[@type='submit']")); 
Actions action = new Actions(driver); 
action.moveToElement(element).click().build().perform() 

    <div class="formRow"> 
    <div class="formRow"> 
    <div class="blueBut1 ml124"> 
    <button class="w150bt fl" type="submit" value="Save Changes"> 
    <a class="fl mt10 ml8" href="/Profile/view?id=&altresid=" rel="last"> 
    </div> 
    </div> 
    </form> 
    </div> 
    </div> 
    </div> 
+0

查看'driver.findElements(By.xpath(「.//*[@type ='submit']」))。length的輸出並檢查多個元素是否與您的描述匹配 –

+0

嘗試xpath //按鈕[@ value ='保存更改'和@ type ='submit']或//按鈕[@ value ='保存更改] – iamsankalp89

回答

-1

試試下面的代碼: -

WebElement element = driver.findElement(By.xpath("//button[@type='submit' and @value='Save Changes']")); 
JavascriptExecutor executor = (JavascriptExecutor)driver; 
executor.executeScript("arguments[0].click();", element); 
+0

使用JSE不是一種好的做法。這不是用戶可以執行的場景。更好的做法是找出實際問題並解決問題,以便腳本以用戶的方式與頁面交互。 – JeffC

0

嘗試等待元素變爲可點擊。

WebDriverWait wait = new WebDriverWait(driver, 20); 
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[@type='submit']"))).click(); 
0

試試這個XPath的與等待

//button[@value='Save Changes'] 
//button[@value='Save Changes' and @type='submit'] 

使用此代碼

WebElement submitButton= driver.findElement(By.xpath("//button[@value='Save Changes']")); 
WebDriverWait waitForElement = new WebDriverWait(driver, 30); 
waitForElement.until(ExpectedConditions.elementToBeClickable(submitButton))).click(); 

WebElement submitButton= driver.findElement(By.xpath("//button[@value='Save Changes' and @type='submit']")); 
WebDriverWait waitForElement = new WebDriverWait(driver, 30); 
waitForElement.until(ExpectedConditions.elementToBeClickable(submitButton))).click();