Webelement.Click() - 在 Webelement.Click() 上获取异常,尽管它单击元素
Webelement.Click() - Getting exception on Webelement.Click() though it clicks the Element
元
OS: Windows
硒版本:2.53.1.0
IDE: Visual Studio 2013
浏览器:Internet Explorer 11 版本 11.420
当我尝试单击网页上的某个元素时出现异常。单击 link 并打开对话框时会发生这种情况。 Webelement.click() 函数单击元素并打开模态对话框,但 Click() 需要时间 return 并最终将异常记录为 'The HTTP request to the remote WebDriver server for URL "" 60 秒后超时。'
预期行为:
It should click the "Firefox Beta" download button and "IE tool bar" with RUN and SAVE option will appear
实际行为:
It clicks the "Firefox Beta" download button and "IE tool bar" is coming. But downloadElement.Click() waits for 60 seconds and throws exception.
重现步骤:
下面是代码片段:
string url = "https://www.mozilla.org/en-US/firefox/channel/#beta";
try{
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(url);
Thread.Sleep(5000);
IWebElement downloadElement = driver.FindElement(By.XPath("//div[@id='download-button-desktop-beta']/ul/li/a/strong"));
Thread.Sleep(5000);
downloadElement.Click();
}catch{
//catch block
}
您可以在 downloadElement.Click() 之后添加隐式等待并等待模态对话框完全加载。
尝试给出这个 xpath 而不是那个。
IWebElement downloadElement = driver.FindElement(By.XPath("/html/body/div[2]/div/main/section[1]/div/div/ul/li[1]/a/strong"));
有时他们的一些问题是 IE11 selenium 无法按预期工作。所以我在某些情况下使用双击而不是单击。
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("/html/body/div[2]/div/main/section[1]/div/div/ul/li[1]/a/strong"))).doubleClick().perform();
尝试使用两者,希望它会有所帮助
试试这个。它对我有用 -
package sbps;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class cvs_signup
{
public static void main(String[] args) {
String url = "https://www.mozilla.org/en-US/firefox/channel/#beta";
try{
WebDriver driver = new InternetExplorerDriver();
driver.get(url);
Thread.sleep(5000);
WebElement downloadElement = driver.findElement(By.xpath("(//a[@href='https://download.mozilla.org/?product=firefox-beta-stub&os=win&lang=en-US'])[last()]"));
Thread.sleep(5000);
downloadElement.click();
}catch(Exception e){
//catch block
}
}
}
元
OS: Windows 硒版本:2.53.1.0 IDE: Visual Studio 2013 浏览器:Internet Explorer 11 版本 11.420
当我尝试单击网页上的某个元素时出现异常。单击 link 并打开对话框时会发生这种情况。 Webelement.click() 函数单击元素并打开模态对话框,但 Click() 需要时间 return 并最终将异常记录为 'The HTTP request to the remote WebDriver server for URL "" 60 秒后超时。'
预期行为:
It should click the "Firefox Beta" download button and "IE tool bar" with RUN and SAVE option will appear
实际行为:
It clicks the "Firefox Beta" download button and "IE tool bar" is coming. But downloadElement.Click() waits for 60 seconds and throws exception.
重现步骤:
下面是代码片段:
string url = "https://www.mozilla.org/en-US/firefox/channel/#beta";
try{
IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(url);
Thread.Sleep(5000);
IWebElement downloadElement = driver.FindElement(By.XPath("//div[@id='download-button-desktop-beta']/ul/li/a/strong"));
Thread.Sleep(5000);
downloadElement.Click();
}catch{
//catch block
}
您可以在 downloadElement.Click() 之后添加隐式等待并等待模态对话框完全加载。
尝试给出这个 xpath 而不是那个。
IWebElement downloadElement = driver.FindElement(By.XPath("/html/body/div[2]/div/main/section[1]/div/div/ul/li[1]/a/strong"));
有时他们的一些问题是 IE11 selenium 无法按预期工作。所以我在某些情况下使用双击而不是单击。
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("/html/body/div[2]/div/main/section[1]/div/div/ul/li[1]/a/strong"))).doubleClick().perform();
尝试使用两者,希望它会有所帮助
试试这个。它对我有用 -
package sbps;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class cvs_signup
{
public static void main(String[] args) {
String url = "https://www.mozilla.org/en-US/firefox/channel/#beta";
try{
WebDriver driver = new InternetExplorerDriver();
driver.get(url);
Thread.sleep(5000);
WebElement downloadElement = driver.findElement(By.xpath("(//a[@href='https://download.mozilla.org/?product=firefox-beta-stub&os=win&lang=en-US'])[last()]"));
Thread.sleep(5000);
downloadElement.click();
}catch(Exception e){
//catch block
}
}
}