0

我知道可以找到類似的問題,但沒有人提供了備用解決方案。請耐心等待。上下文的替代方法在Chrome瀏覽器中:Selenium-WebDriver- Java

經過一番研究,我意識到這是不可能在Chrome browser.For前自動contextClick:

如果我需要下面的代碼和瀏覽器執行必須是CHROME-

 
driver.get("https://www.google.com"); 

Actions ac= new Actions(driver);   

ac.moveToElement(driver.findElement(By.id("hplogo"))).contextClick().sendKeys(Keys.ARROW_DOWN).build().perform();

會如果我可以選擇使用contextClick選項,將會很有幫助。 謝謝

+0

你究竟在做什麼?什麼動作? –

回答

0

在我的Chrome瀏覽器上,contextClick工作正常。嘗試下面的代碼行,它可能會解決您的問題。 ()。)()。)contextClick()。sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build()。perform();方法返回一個數組。

0

你試圖做背景僅限點擊,然後

Actions conClick=new Actions(driver); 

    //i am expecting you are try to perform right click id = hplogo 
    conClick.contextClick(driver.findElement(By.id("hplogo"))).build().perform(); 

    // if you want to select or click any option in this context menu 
    // go for click with specific location, no need of keys 
    // if required use sleep before click 
    driver.findElement(By.id("required location")).click(); 

如果上下文後點擊上面點擊時無法正常運行,那麼你也可以試試下面的方法

 Actions conClick1=new Actions(driver); 
    //i am expecting you are try to perform right click id = hplogo 
    //after context click moving to 25 vertically, may be second option in context menu and clicking 
    conClick1.contextClick(driver.findElement(By.id("hplogo"))).moveByOffset(5, 25).click().build().perform(); 

謝謝你, Murali

相關問題