2015-10-21 51 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

感謝您的幫助,但對不起,此代碼無法正常工作 –