Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法双击chrome selenium c#_C#_Selenium_Selenium Webdriver - Fatal编程技术网

有没有办法双击chrome selenium c#

有没有办法双击chrome selenium c#,c#,selenium,selenium-webdriver,C#,Selenium,Selenium Webdriver,我正在写一个测试脚本。我的测试在某一点失败,因为按钮需要单击两次 我临时更改了代码,使其包含同一段代码两次,这就成功了。但是有没有办法引入双击呢 代码: webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click(); webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click(); 这是完整的代码: using System; using

我正在写一个测试脚本。我的测试在某一点失败,因为按钮需要单击两次

我临时更改了代码,使其包含同一段代码两次,这就成功了。但是有没有办法引入双击呢

代码:

webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
这是完整的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;

namespace Exercise1
{
    class RunPath
    {

            static void Main()
            {

                IWebDriver webDriver = new ChromeDriver();
                webDriver.Navigate().GoToUrl("https://energy.gocompare.com/gas-electricity");
                webDriver.Manage().Window.Maximize();
            String title = webDriver.Title;
            String expectedTitle = "Utilities from Go Compare";
            if (title.Contains(expectedTitle))
            {
                Console.WriteLine("Tile is matching with expected value");
            }
            else
            {
                Console.WriteLine("Tile is matching with expected value");
            }
            webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
            webDriver.FindElement(By.XPath(".//input[@type = 'text']")).SendKeys("W30PN#");
            webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
            webDriver.FindElement(By.XPath(".//input[@type = 'text']")).Clear();
            webDriver.FindElement(By.XPath(".//input[@type = 'text']")).SendKeys("W30PN");
            webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
            webDriver.FindElement(By.XPath(".//button[@type = 'submit']")).Click();
你可以参考这个

使用动作类:

    Actions action  = new Actions(driver);
    action.MoveToElement("Web Element To Click").DoubleClick().Perform();
使用JavaScriptExecutor:

((JavascriptExecutor)driver).ExecuteScript("arguments[0].dblclick();", "Element to Click");

你可以试试这个代码。您只需向下滚动到特定元素(在您的情况下是继续按钮),而不是
双击

您可以尝试的代码:

webDriver.Navigate().GoToUrl("https://energy.gocompare.com/gas-electricity");
IWebElement postcode =  
webDriver.FindElement(By.CssSelector("input[placeholder='Postcode']"));
postcode.Clear();
postcode.SendKeys("B33 8TH");
IWebElement email =  webDriver.FindElement(By.CssSelector("input[placeholder='Email (Optional)']"));
email.Clear();
email.SendKeys("L.dockster@stackoverflow.com");
((IJavascriptExecutor) webDriver).ExecuteScript("window.scrollTo(0, document.body.scrollHeight - 700)");
webDriver.findElement(By.XPath("//button[text()='Continue']")).Click();

我介绍了你的代码,但它似乎没有做双击。当我把同一段代码像上面那样写了两遍,它就工作得很好了,你说的“它似乎没有双击”是什么意思?如果您遇到异常,请分享更多详细信息。?@L.Dockster您可以将更新的语法引用引用引用到c#我已粘贴了上面代码的其余部分。我没有得到异常,但一旦我输入了数据字符串,我的最后一段代码就会运行并单击“继续”按钮。此按钮需要单击两次,才能进入下一页。对于你的代码,它不会进入下一页,因为我相信它不会重复click@L.Dockster这些是双击的唯一可能方法。参考另一个。当我手动操作时,我只单击了一次,它就工作了。是的,所以前两次它只执行一次。但是,当它到达第三个按钮时,奇怪的是,它不接受一次单击。我尝试了“继续”按钮,结果相同。我要做的是点击“继续”按钮进入URL,得到一个错误,输入一个不正确的帖子代码,得到一个错误,然后输入一个正确的帖子代码,然后从我的最终代码继续,这一切都很好。现在,在您的情况下,您可以导航到URL,然后您必须向下滚动以单击“继续”按钮,因为“继续”按钮对我们不可见,显然对浏览器也不可见,因此您可能会遇到此异常:
其他元素收到了单击(x,y)