简体   繁体   English

使用Selenium(C#)将详细信息传递到弹出窗口

[英]Passing details to popup window using Selenium (C#)

I am trying to pass Details like FirstName, LastName etc to the popup window. 我试图将诸如FirstName,LastName等的详细信息传递给弹出窗口。 I am attaching the screenshot as well. 我也附上了屏幕截图。 The problem I am facing is the field name of the LastName is same as the main window, so when I am trying to pass the details, it is getting added to the main window instead of the popup window. 我面临的问题是LastName的字段名称与主窗口相同,因此当我尝试传递详细信息时,它会被添加到主窗口而不是弹出窗口中。 The C# code that I am using is: 我正在使用的C#代码是:

var w = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20));
var copy =w.Until(ExpectedConditions.ElementIsVisible(By.Id("copyButton")));
copy.Click();
Driver.Instance.SwitchTo().Window(Driver.Instance.WindowHandles.Last());
Driver.Instance.Manage().Window.Maximize();
Driver.Instance.FindElement(By.Name("lastname")).SendKeys("Emily");

Here instead of passing to the popup window, it is passing to the main window. 在这里,不是传递到弹出窗口,而是传递到主窗口。

I have also tried to inspect in the popup and tried to copy the xpath: 我也尝试在弹出窗口中检查并尝试复制xpath:

var w = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20));
var copy =w.Until(ExpectedConditions.ElementIsVisible(By.Id("copyButton")));
copy.Click();
Driver.Instance.SwitchTo().Window(Driver.Instance.WindowHandles.Last());
Driver.Instance.Manage().Window.Maximize();
Driver.Instance.FindElement(By.Xpath("//*  [@id="pageBodyNoHeader"]/form/table[2]/tbody/tr[1]/td[2]/input")).SendKeys("Emily");

Over here it says "Syntax error(,) is expected". 在这里说“语法错误(,)是预期的”。

Can someone please help? 有人可以帮忙吗?

在此处输入图片说明

So to Solve your Syntax issue, simply change: 因此,要解决您的语法问题,只需更改:

Driver.Instance.FindElement(By.Xpath("//*  [@id="pageBodyNoHeader"]/form/table[2]/tbody/tr[1]/td[2]/input")).SendKeys("Emily");

To: 至:

Driver.Instance.FindElement(By.Xpath("//*  [@id='pageBodyNoHeader']/form/table[2]/tbody/tr[1]/td[2]/input")).SendKeys("Emily");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM