使用 selemium 自动填充文本框命名地址 forms.office C#
Using selemium autofill textbox Name a address forms.office C#
这是link的mircosoft 没有病毒。
我想要编写应用程序自动填写 Full_Name、地址、电子邮件并单击表单中的按钮
元素输入如下:
<input class="office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius" placeholder="Enter your answer" spellcheck="true" maxlength="4000" aria-labelledby="QuestionId_rbf8060578cb4410ba72d3e97840ebd95">
我试过项目中的代码:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(driverService, options);
driver.Navigate().GoToUrl("https://forms.office.com/Pages/ResponsePage.aspx?id=IWuHvDTxEkyiZY7Sa38PO_KiPmlYCpVOuIi4NlZfBs1UOVlCNlNFUTkyR0IwQVZaVDc2Uk9QUlVBUCQlQCN0PWcu");
IWebElement query = driver.FindElement(By.Id("QuestionId_rbf8060578cb4410ba72d3e97840ebd95"));
query.SendKeys("David Luis");
下一个变化:
IWebElement query = driver.FindElement(By.Name("Full Name"));
结果显示:OpenQA.Selenium.ElementNotInteractableException: '元素不可交互
(会话信息:chrome=91.0.4472.77)'
问题:
请指导我在这种情况下应该由 class 或 id,由 Name
使用
IWebElement query = driver.FindElement(By.Name("Full Name"));
By.name Selenium 中的定位器用于标识网页的元素。此属性可以作为多个标签的一部分提及,例如 、
IWebElement query = driver.FindElement(By.Id("QuestionId_rbf8060578cb4410ba72d3e97840ebd95"));
也是错误的选择,因为 aria-labledby 不是锁定的 Id。
所以有很多可能性:
f.e。你可以给元素一个唯一的id,比如:
<input id="uniqueInputID" class="office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius" placeholder="Enter your answer" spellcheck="true" maxlength="4000" aria-labelledby="QuestionId_rbf8060578cb4410ba72d3e97840ebd95">
IWebElement query = driver.FindElement(By.Id("uniqueInputID"));
你也可以使用 xpath:
IWebElement query = driver.findElement(By.XPath("//*[@id="form-container"]/div/div/div/div/div[1]/div[2]/div[2]/div[2]/div[1]/div/div[2]/div/div/input")
...
您可以在这样的页面上查找最佳实践:https://screenster.io/selenium-locators-best-practices/
我已经尝试使用“xpath”成功了。这很容易理解。以下是我用于该项目的代码:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(driverService, options);
driver.Navigate().GoToUrl("https://forms.office.com/Pages/ResponsePage.aspx?id=IWuHvDTxEkyiZY7Sa38PO_KiPmlYCpVOuIi4NlZfBs1UOVlCNlNFUTkyR0IwQVZaVDc2Uk9QUlVBUCQlQCN0PWcu");
IWebElement query = driver.FindElement(By.XPath("//*[@id=\"form-container\"]/div/div/div/div/div[1]/div[2]/div[2]/div[2]/div[1]/div/div[2]/div/div/input"));
query.SendKeys("David Luis");
感谢支持。
这是link的mircosoft 没有病毒。 我想要编写应用程序自动填写 Full_Name、地址、电子邮件并单击表单中的按钮
元素输入如下:
<input class="office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius" placeholder="Enter your answer" spellcheck="true" maxlength="4000" aria-labelledby="QuestionId_rbf8060578cb4410ba72d3e97840ebd95">
我试过项目中的代码:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(driverService, options);
driver.Navigate().GoToUrl("https://forms.office.com/Pages/ResponsePage.aspx?id=IWuHvDTxEkyiZY7Sa38PO_KiPmlYCpVOuIi4NlZfBs1UOVlCNlNFUTkyR0IwQVZaVDc2Uk9QUlVBUCQlQCN0PWcu");
IWebElement query = driver.FindElement(By.Id("QuestionId_rbf8060578cb4410ba72d3e97840ebd95"));
query.SendKeys("David Luis");
下一个变化:
IWebElement query = driver.FindElement(By.Name("Full Name"));
结果显示:OpenQA.Selenium.ElementNotInteractableException: '元素不可交互 (会话信息:chrome=91.0.4472.77)'
问题: 请指导我在这种情况下应该由 class 或 id,由 Name
使用IWebElement query = driver.FindElement(By.Name("Full Name"));
By.name Selenium 中的定位器用于标识网页的元素。此属性可以作为多个标签的一部分提及,例如 、
IWebElement query = driver.FindElement(By.Id("QuestionId_rbf8060578cb4410ba72d3e97840ebd95"));
也是错误的选择,因为 aria-labledby 不是锁定的 Id。
所以有很多可能性:
f.e。你可以给元素一个唯一的id,比如:
<input id="uniqueInputID" class="office-form-question-textbox office-form-textfield-input form-control office-form-theme-focus-border border-no-radius" placeholder="Enter your answer" spellcheck="true" maxlength="4000" aria-labelledby="QuestionId_rbf8060578cb4410ba72d3e97840ebd95">
IWebElement query = driver.FindElement(By.Id("uniqueInputID"));
你也可以使用 xpath:
IWebElement query = driver.findElement(By.XPath("//*[@id="form-container"]/div/div/div/div/div[1]/div[2]/div[2]/div[2]/div[1]/div/div[2]/div/div/input")
...
您可以在这样的页面上查找最佳实践:https://screenster.io/selenium-locators-best-practices/
我已经尝试使用“xpath”成功了。这很容易理解。以下是我用于该项目的代码:
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
var driver = new ChromeDriver(driverService, options);
driver.Navigate().GoToUrl("https://forms.office.com/Pages/ResponsePage.aspx?id=IWuHvDTxEkyiZY7Sa38PO_KiPmlYCpVOuIi4NlZfBs1UOVlCNlNFUTkyR0IwQVZaVDc2Uk9QUlVBUCQlQCN0PWcu");
IWebElement query = driver.FindElement(By.XPath("//*[@id=\"form-container\"]/div/div/div/div/div[1]/div[2]/div[2]/div[2]/div[1]/div/div[2]/div/div/input"));
query.SendKeys("David Luis");
感谢支持。