2015-10-21 19 views
-3

我正在尝试创建xpath this(Unscheduled Visitor Check-In)按钮。我无法找到按钮名称或ID。任何人都可以帮我解决这个问题。将会明白这一点。请参阅附件。我如何在此代码下创建xpath

<div id="SAFEControl307369" class="buttontextactivestyle" uniquefieldid="307369" onselectstart="return false" onchange="setAttribute('IsModified','1');" onclick=" document.body.style.cursor = 'wait'; window.location.href = 'QSForm.aspx?FormID=194&Hidden=1';return false;" datatype="" boundcolumn="" ismodified="0" style="position:absolute;left:280px;top:5px;height:0px;width:250px; ;" caption="" tabindex="-1"> 
<table width="100%" cellspacing="0" cellpadding="0" border="0"> 
<tbody> 
<tr style="height:20px;cursor:pointer;"> 
<td class="buttonleftactivestyle"/> 
<td class="buttonmiddleactivestyle" align="center"> 
<div>Unscheduled Visitor Check-In</div> 
[Screenshot of the application with xpath][1] 
+0

你有什么试过,结果是什么?正如你在学校所做的那样,请展示你的工作。 :)这是在SO上获得问题的过程中的一部分。这对你很有帮助,因为它会迫使你调查自己的问题并思考问题。这也向读者证明你做了功课,并做出了合理的尝试来回答你自己的问题。第三,它可以帮助读者找到和诊断问题,为您提供更好的答案,减少浪费时间。 – JeffC

回答

0

请使用下面的XPath:

//div[contains(.,'Unscheduled Visitor Check-In')] 

你可以试试下面的代码:

WebElement element= driver.findElement(By.xpath("Your XPath")); 

JavascriptExecutor executor = (JavascriptExecutor) driver; 
executor.executeScript("arguments[0].click();", element); 

随意改变定位在上面的代码。尝试使用firepath提供的xpath,如图所示。

+0

谢谢,我会尝试它,然后更新到你 –

+0

欢迎Satyajit ..你可以请接受的答案,如果它真的适合你 –

+0

对不起兄弟,通过输入错误我回复说“现在正在工作”我的回复将是“它不工作“,我对此非常抱歉。 –

0
IWebElement element = driver.FindElement(By.XPath("//div[@id='SAFEControl307369']/table/tbody/div")); 

当您检查元素时,您需要查看创建XPath的尝试。

+0

感谢您的帮助,但对不起,此代码无法正常工作 –