Tag: selenium webdriver

等待页面加载

我正在尝试创建一个等待页面加载javascript ,但我遇到了错误。 可能我没有正确使用该方法。 public static void WaitForLoad(this IWebDriver driver, int timeoutSec = 15) { WebDriverWait wait = new WebDriverWait(driver, new TimeSpan(0, 0, timeoutSec)); wait.Until(wd => wd.ExecuteJavaScript(“return document.readyState”) == “complete”); } 错误是: The type arguments for method ‘WebdriverExtensions.ExecuteJavaScript(IWerbDriver,string,params object[]’ cannot be inferred from the usage.Try specifying the type arguments explicity)

如何在Selenium中设置ChromeDriver的端口?

作为一些背景,我正在玩BrowserMob代理,我被端口设置阻止。 所以我想知道如何自己设置一个端口。 Server srv = new Server(@”C:\BMob\browsermob\bin\browsermob-proxy.bat”); srv.Start(); Client cln = srv.CreateProxy(); cln.NewHar(“BOWZA”); ChromeOptions co = new ChromeOptions(); Proxy seleniumProxy = new Proxy { HttpProxy = cln.SeleniumProxy }; co.Proxy = seleniumProxy; ChromeDriver cDriver = new ChromeDriver(co); // What do I do now…? 对不起,我没有找到任何记录此事的内容

使用Selenium使用Webdriver的Timeout的最佳方法是什么?

我遇到了一个问题。 我的网页有一个DropDownList控件。 一旦DropDownList值改变(通过选择不同的值),页面将刷新并呈现内容。 然后我必须使用Thread.Sleep(2000); 在它和FindElement之前。 我的问题:等待页面加载的最佳方法是什么? 我的代码中有很多Thread.Sleep(2000)实例,我开始认为这不是解决问题的最佳方法。 这是我的代码: [TestInitialize()] public void Setup() { if (BaseIntegrationTest.browserType.Equals(BaseIntegrationTest.IE)) { driver = new InternetExplorerDriver(); } else if (BaseIntegrationTest.browserType.Equals(BaseIntegrationTest.CHROME)) { //driver = new ChromeDriver(); } else if (BaseIntegrationTest.browserType.Equals(BaseIntegrationTest.FIREFOX)) { driver = new FirefoxDriver(); } } 第二部分: [TestMethod] public void testVerifyData() { // ………………. // ………………. driver.FindElement(By.XPath(“//*[@id=’ctl00_NavigationControl1_lnke’]”)).Click(); Thread.Sleep(2000); //select from the […]

无法在Selenium中启动Chrome驱动程序

我总是能够在本地启动chromedriver服务器,但之后我尝试远程执行此操作,从那时起我无法启动它。 我重新安装了chrome以及chrome驱动程序,但似乎没有解决这个问题。 即使我给出了我的驱动程序的路径它也不会启动。 using OpenQA.Selenium; using OpenQA.Selenium.Support; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.IE; using OpenQA.Selenium.Chrome; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenQA.Selenium.Safari; using OpenQA.Selenium.Interactions; namespace TestWebDriver { class Program { static void Main(string[] args) { var driver = new ChromeDriver(@”C:\Users\laurens.putseys\Documents\Visual Studio 2015\Projects\TestWebDriver\packages\Selenium.WebDriver.ChromeDriver.2.21.0.0\driver\”); driver.Url = “http://google.be”; Console.ReadLine(); driver.Quit(); } } } 我得到的错误如下: An […]

如何使用Selenium将样式属性设置为元素?

driver.SwitchTo().Frame(“contentFrame”); IWebElement str = driver.FindElement(By.XPath(“//*[@id=’dvCustomDateRange’]”)); 我需要从style =“display:none;”更改style属性 to style =“display:block;”。 这是元素: 任何想法如何使用Selenium这样做? 我尝试使用getAttribute和getCssValue方法来更改值但没有结果。

使用Selenium Webdriver和Safari

我正在使用Visual Studio Express 2012开发Selenium Webdriver C#。 我安装了最新的safari浏览器,我从Apple创建了扩展的开发人员证书,我构建了扩展并安装它。 但即使在那之后,我也无法将URL发送到浏览器。 浏览器成功启动,但之后我没有得到任何日志。 错误消息是: 附加信息:未从Safari扩展程序接收连接。 请确认它已正确安装且版本正确。 我使用的代码: IWebDriver driver = new SafariDriver(); driver.Navigate().GoToUrl(“http://www.google.com”); Safari无法连接到服务器。 请帮帮我,谢谢。

在selenium / webdriver c#中循环遍历多个moveToElement

我试图通过web元素点击鼠标内的所有这些嵌套链接。 第一次迭代起作用,但在此之后停止。 我试过添加Thread.Sleep(xxxx); 但这也不起作用。 这是我的方法: public static bool TestFindAssets() { bool result = false; Actions action = new Actions(driver); var findAssetsClick = driver.FindElement(By.XPath(“/html/body/div/header/nav/ul/li[3]/a”)); var home = driver.FindElement(By.LinkText(“Home”)); try { for (int i = 1; i < 13; i++) { action.MoveToElement(findAssetsClick).Perform(); //Find Assets Link action.MoveToElement(driver.FindElement(By.XPath("xpath"))).Perform(); //By Type Link action.MoveToElement(driver.FindElement(By.XPath("otherPath"+i))).Click().Build().Perform(); //list of links } result = true; […]

如何在定位元素之前等待加载帧?

我正在等待Selenium在等待另一个元素之前切换更改帧。 即 var wait = new WebDriverWait(driver, 15); wait.Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.Id(“frameA”)); var wait2 = new WebDriverWait(driver, 15); // wait for element within frameA to exist wait2.Until(ExpectedConditions.ElementExists(By.Id(“elementA”))); 如果我抛入一个简单的Thread.Sleep(1000); 在第二次等待之前它运行正常,但没有它我得到以下错误: ‘unknown error: unhandled inspector error: {“code”:-32000,”message”:”Cannot find context with specified id”} enter code here 有没有更好的方法等待帧上下文切换完成之后再等待该帧中的元素被填充?

如何在C#中使用Selenium WebDriver获取当前窗口的URL?

在登录时我的应用程序中,它会导航到另一个页面。 现在我需要在selenium C#中使用WebDriver获取新的URL。 我找不到任何function来做到这一点。 我已经尝试过driver.Url , driver.getLocation()和driver.getCurrentUrl() ,但我的C#应用​​程序中没有任何工作。 那么有可能以某种方式得到当前的URL吗? 导航后?

Selenium C#打开新标签CTRL + T不使用CHROME

static void Main() { IWebDriver driver = new ChromeDriver(); driver.Navigate().GoToUrl(“http://google.com”); IWebElement body = driver.FindElement(By.TagName(“body”)); body.SendKeys(Keys.Control + “t”); } 这是我试图用来打开一个新选项卡而不能正常运行的代码,我没有得到任何错误,驱动程序打开谷歌,这就是所有….我已经搜索了很多,发现很多教程甚至video人们使用完全相同的代码,它适用于他们,但对我来说它没有,我无法弄清楚… 我尝试将Keys.Shift +“t”发送到搜索字段并且它可以工作,它在字段中写入大写字母T. 我也试过了 Actions act = new Actions(driver); act.KeyDown(Keys.Control).SendKeys(“t”).Perform(); 它仍然无法正常工作,但如果我将Keys.Control更改为Keys.Shift它写入,似乎没有任何涉及Keys.Control工作! 编辑:我尝试使用IE驱动程序运行代码并在那里工作,它会打开新选项卡,但它不会在Chrome上打开新选项卡?