C# Can´;不要按单选按钮
我有下面的HTML文件,我想点击输入名为optUsoTabaco的单选按钮。但我没有成功C# Can´;不要按单选按钮,c#,selenium,C#,Selenium,我有下面的HTML文件,我想点击输入名为optUsoTabaco的单选按钮。但我没有成功 <section id="bloco-cadastro" ng-show="vm.modo.edicao || vm.modo.novo" class=""> <ul class="passos"> </ul> <form name="formSimulador" novalidate="" class="ng-val
<section id="bloco-cadastro" ng-show="vm.modo.edicao || vm.modo.novo" class="">
<ul class="passos">
</ul>
<form name="formSimulador" novalidate="" class="ng-valid-pattern ng-valid-maxlength ng-valid-cpf ng-invalid ng-invalid-required ng-dirty ng-valid-parse ng-valid-date">
<p class="aviso-campos-assinalados text-muted">Os campos assinalados com * são obrigatórios.</p>
<h3 class="text-info titulo-bloco page-header">Dados do Cliente</h3>
<fieldset class="simulador small">
<input type="hidden" name="hidSimulacaoId" ng-model="vm.viewmodelsimulacao.simulacaoId" class="ng-pristine ng-untouched ng-valid ng-empty">
<fieldset ng-disabled="!vm.viewmodelsimulacao.formularioEditavel">
<div class="row passo-1" id="passoUm">
</div>
<div class="row dados-solicitante">
</div>
<div class="row dados-estudo">
</div>
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 form-group">
<label>Sexo *</label>
<div class="radio md-radio">
<label class="separador_direita ativo"><input type="radio" value="F" ng-model="vm.viewmodelsimulacao.sexo" name="optSexo" required="" class="ng-touched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required">Feminino</label>
<label class="separador_esquerda "><input type="radio" value="M" ng-model="vm.viewmodelsimulacao.sexo" name="optSexo" required="" class="ng-pristine ng-untouched ng-not-empty ng-valid ng-valid-required">Masculino</label>
</div>
<div class="has-error ng-hide" ng-show="formSimulador.$submitted || formSimulador.optSexo.$touched">
<span class="control-label ng-hide" ng-show="formSimulador.optSexo.$invalid">
Valor Obrigatório
</span>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 form-group">
<label>Fumante? *</label>
<div class="radio md-radio">
<label class="separador_direita "><input type="radio" value="S" ng-model="vm.viewmodelsimulacao.fazUsoDeTabaco" name="optUsoTabaco" required="" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required">Sim</label>
<label class="separador_esquerda "><input type="radio" value="N" ng-model="vm.viewmodelsimulacao.fazUsoDeTabaco" name="optUsoTabaco" required="" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required">Não</label>
</div>
<div class="has-error ng-hide" ng-show="formSimulador.$submitted || formSimulador.optUsoTabaco.$touched">
<span class="control-label" ng-show="formSimulador.optUsoTabaco.$invalid">
Valor Obrigatório
</span>
</div>
</div>
</div>
</fieldset>
<!-- ngIf: vm.botoesAcao --><div class="row ng-scope" ng-if="vm.botoesAcao">
</fieldset>
</form>
</section>
Os campos assinalados com*são obrigatórios
护墙板做客户
性感*
女性
男性的
奥布里加特罗河谷酒店
富曼特*
模拟
Não
奥布里加特罗河谷酒店
我尝试访问名为optUsoTabaco的单选按钮,代码如下:
driver.FindElement(By.CssSelector("#bloco-cadastro > form > fieldset > fieldset > div:nth-child(4) > div:nth-child(2) > div.radio.md-radio > label.separador_direita.ativo"));
------ x ------
driver.FindElement(By.XPath("//*[@id='bloco - cadastro']/form/fieldset/fieldset/div[4]/div[2]/div[1]/label[2]/input")).Click();
------ x ------
driver.FindElement(By.XPath("//*[@id='bloco - cadastro']/form/fieldset/fieldset/div[4]/div[2]/div[1]/label[2]")).Click();
------ x ------
IList<IWebElement> radioBtn = driver.FindElements(By.Name("optUsoTabaco"));
radioBtn.ElementAt(1).Click();
driver.FindElement(通过.CssSelector(“#bloco cadastro>form>fieldset>fieldset>div:nth child(4)>div:nth child(2)>div.radio.md-radio>label.separador_direita.ativo”);
------x------
FindElement(By.XPath(“//*[@id='bloco-cadastro']/form/fieldset/fieldset/div[4]/div[2]/div[1]/label[2]/input”)。单击();
------x------
FindElement(By.XPath(“//*[@id='bloco-cadastro']/form/fieldset/fieldset/div[4]/div[2]/div[1]/label[2]”)。单击();
------x------
IList radioBtn=driver.FindElements(By.Name(“optUsoTabaco”);
radioBtn.ElementAt(1).单击();
在所有这些情况下,我都遇到了错误:“WebDriver.dll中发生了“OpenQA.Selenium.NoSuchElementException”类型的异常,但未在用户代码中处理。其他信息:没有此类元素:无法定位元素”
我做错了什么
我已经尝试了10秒的等待,但没有解决问题您正在编写的所有xpath和cssSelector都是绝对的,使用起来没有什么意义。尽管他们是正确的。我看不出他们有什么问题 我相信会涉及iframe/frameset,因此您必须将web驱动程序的焦点切换到特定的iframe 您可以尝试的代码:
driver.SwitchTo().Frame(driver.FindElement(By.Xpath("xpath of frame")));
您可以使用CSS选择器 如果要选择Sim单选按钮,请使用
div.row > div > div > label > input[name="optUsoTabaco"][value="S"]
div.row > div > div > label > input[name="optUsoTabaco"][value="N"]
如果要选择Não,则使用
div.row > div > div > label > input[name="optUsoTabaco"][value="S"]
div.row > div > div > label > input[name="optUsoTabaco"][value="N"]
我用JavaScript解决了这个问题
IWebElement st_2 = driver.FindElement(By.Name("optUsoTabaco"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", st_2);
这里有4个复选框,你想点击哪一个?NãoCan你能用iframe/frameset更新我们吗?我有一个网站,里面有一个使用iframe的表单。登录后,我在代码中做的第一件事就是切换到框架。driver.SwitchTo().Frame(driver.FindElement(By.Id(“IframeLegado”));在此之后,我填充了一些字段,但无法对这个字段执行任何操作。请看,您在一个id为“IframeLegado”的iframe中,在所有交互之后,您必须使用以下代码将web驱动程序的焦点切换回父级:driver.SwitchTo().DefaultContent();并将驱动程序焦点切换到您现在想要交互的iframe,这是有意义的?但首先您必须在iframe内部,然后只有您才能使用river.findelelement(By.XPath(//label[contains(text(),'Não')))))。单击();此代码错误相同:WebDriver.dll中出现“OpenQA.Selenium.ElementNotVisibleException”类型的异常,但未在用户代码中处理其他信息:元素不可见您是否将焦点切换到帧?