I am trying to automate an application using selenium Webdriver. I frequently come across scenarios where click action does not work on the WebElements.
For instance , in the html block that looked something like :
<div id=staticid>
<table>
<tbody>
<tr id="tr1" class="class1" tabindex="-1" data-recordindex="0" data-recordid="1" data-boundview="gridview-1211" role="row">
<td id="td1" class="class2 " role="gridcell">
<div class="class3 " style="text-align:left;" unselectable="on">Content 1</div>
<td id="td2" class="class6" role="gridcell">
<div class="class5" style="text-align:center;" unselectable="on">
<img class="class4" src="chekboximage">
</div>
</td>
<td id="td3" class="class8" role="gridcell">
<div class="class5" style="text-align:center;" unselectable="on">
<img class="class4" src="checkboximage">
</div>
</td>
</tr>
</tbody>
</table>
</div>
The ids are dynamically generated and the classes are like "grid-inner.." so on. (I ve replaced them to make it smaller)
The last two elements appear as checkboxes.
On clicking the block, the class of the td block changes and the the checkbox appears to be clicked.
I tried to click on the checkboxes using driver.findElement(By.xpath()),csspath and everything. The click action seems to be carried out successfully but the desired result,that is ,the checkbox being checked does not happen.
I verified my xpath and csspaths using Selenium IDE. The Element gets located correctly using the "Find" option. Click action also gets performed ,but the checkboxes remain unchecked.
I ve been trying to get this done for almost a week now.
Can anyone please help me out?
The code did seem to change the image on click (I compared the image source before and after a click) . But there were no visible "onclick()" calls (I am not sure if there are other ways of invoking java script fuctions on click.Please do let me know if there are ). Anyway , I tried clicking on the block. it works with Se-IDE and Se-IEDriver but not in FireFoxDriver.
Try driver.findElement(By.xpath()).sendKeys(Keys.ENTER); this also does the same as click but with keyboard stroke. Hope it works.
Related
I have been trying this for a few days and am completely stuck. If anybody could help me out I would be very grateful; Im using VB.NET.
The HTML Code:
<tbody>
<tr>
<td class="chat-attachment-cell"></td>
<td class="chat-input-cell">
<textarea class="chat-message-input"></textarea>
</td>
<td class="chat-send-cell"><a href="#" class="chat-send-button"> alt="Send" width="66" height="66" border="0">
</a>
</td>
</tr>
</tbody>
The text box I need to input into is this bit
<textarea class="chat-message-input"></textarea>
Thankyou in advance for any help provided
You select the element then change the .innertext property with what you want.
There are multiple ways to do it, and I can't give you an example because I don't know what you are using nor the whole html, but for example it could look like this:
WebBrowser1.Document.GetElementById("someid").InnerText="Sometext"
For start, you can try looking how the collection of elements you get looks, then you should be able to figure out what to do next.
Dim test = WebBrowser1.Document.GetElementsByTagName("textarea")
For example on this page:
Dim test = WebBrowser1.Document.GetElementsByTagName("tbody")
test(1).InnerText = "Hi there"
I'm trying to copy text from a website with the following code and I want it to automatically click the "NEXT" button at the end of the table, without clicking it the code works just fine but when I add the last line to click it gives the error:
"Message: Element is no longer attached to the DOM Stacktrace: at
fxdriver.cache.getElementAt
(resource://fxdriver/modules/web-element-cache.js:9354)
at Utils.getElementAt (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:8978)
at WebElement.getElementText (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:11965)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:12534)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:12539)
at DelayedCommand.prototype.execute/< (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver#googlecode.com/components/command-processor.js:12481)"
The code I'm using is:
driver = webdriver.Firefox()
driver.get("https://it.website.com/Statistics")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
Next_first = 0
Next_first = driver.find_elements_by_id("next")[0]
data_vector [i]=driver.find_elements_by_class_name("tn")[i].text
Next_first.click()
While the website code is:
<tr>
<td class="tn"> text
</td>
<table class="table class" id="table id">
<thead>...code for table title...
</thead>
<tbody>
<tr>
<td class="tn">data
</td>
</tr>
</tbody>
<dd>
<a class="option clickable" id="next" data-page="1">NEXT</a>
</dd>
</tr>
Is there more than the html-source, like javascript?
Because the input could be detached by javascript, which means you have to wait for it to load properly ( driver.implicitly_wait(#seconds) )
here the link to the discription of "implicit-waits"
The second solution could be that you have to clear the cache/cookies of the webdriver before testing, which is described here
I've located a button, first time around when it is rendered with a text on it as 'Kill' with---> .//tr[1]/td[4]/div/button[text()='Kill'].
My html was like...
<tbody>
<tr class="GPBYFDECG GPBYFDEJG" __gwt_row="0" __gwt_subrow="0">
<td class="GPBYFDEBG GPBYFDEDG GPBYFDEEG GPBYFDEKG">
<td class="GPBYFDEBG GPBYFDEDG GPBYFDEKG">
<td class="GPBYFDEBG GPBYFDEDG GPBYFDEKG">
<td class="GPBYFDEBG GPBYFDEDG cellkillbutton GPBYFDEKG">
<div style="outline-style:none;" __gwt_cell="cell-gwt-uid-339" tabindex="0">
<button type="button" style="width: 50px;color:white;" tabindex="-1">Kill</button>
</div>
</td>
When user clicks on the button, the text on it just changes to 'UnKill' and nothing in HTML changes, but when I modify the xpath to
.//tr[1]/td[4]/div/button[text()='UnKill'].
It doesn't work at all. Why ? Even when I refresh the page and go in to the firebug and check it, it does not work.
Some time there might be chances that your element state get changed if you are doing actions with same element . So for your case if it is doing click on button labeled as "Kill"
then check that your button is clickable or not by putting some ExplicitWait like
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(".//tr[1]/td[4]/div/button[contains(text(),'Kill')]")));
driver.findElement(By.xpath(".//tr[1]/td[4]/div/button[contains(text(),'Kill')]")).click();
When you click on the button as "Kill" it becomes hidden and some other button gets activated at the same UI location with the text "UnKill". In this case the xpath for this two elements are different. For your second run try finding the xpath of the button/element with text "Unkill" & try to click. It should work.
I tired a lot to get the xpath of the div which displays as "カーク商品掲載カタログ Online" on screen, but I'm not able to. The application is made using ZK framework hence it has random ID's.
<td z.type="Lic" id="z_mk_qr1" class="activeCatalogVersionTreeItem z-list-cell" z.zcls="z-list-cell" onmouseout="dragHoverClick( $e('z_mk_qr1'), event, true, null, 0);" onmouseover="dragHoverClick( $e('z_mk_qr1'), event, false, 'PerspectiveDND', 500);">
<div id="z_mk_qr1!cave" class="z-list-cell-cnt z-overflow-hidden">カーク商品掲載カタログ Online
<span id="z_mk_rr1" class="catalog-mnemonic-label z-label" z.zcls="z-label"> (STO-O)
</span>
</div>
</td>
I thought the xpath should be something like //div[contains(text(),'カーク商品掲載カタログ Online')], but it doesn't work.
Thanks!
Try the below cssSelector to identify the required element.
td.activeCatalogVersionTreeItem div.z-list-cell-cnt
You may use partial text match in this case as follows:
//div[contains(text(), 'Online')]
Check the link below for more:
https://sqa.stackexchange.com/questions/10342/how-to-find-element-using-contains-in-xpath
I want to get tooltip information enabling on JavaScript. I have tried with below code but its shown null every time.
Java Code:
Actions action = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//*[#id='content']/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/table/tbody/tr[1]/td[2]/span/div/a"));
action.moveToElement(element).build().perform();
System.out.println(driver.findElement(By.xpath("//*[#id='content']/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/table/tbody/tr[1]/td[2]/span/div/a")).getAttribute("data-original-title"));
HTML Code is:
<tr class="single" name="Tasks_59c777d9-8d16-694a-7307-52caad36d751">
<td>
</td>
<td data-type="custom_task_name">
<span class="list" sfuuid="3840" data-original-title="">
<div class="ellipsis_inline" data-original-title="">
Task Testing
<br/>
Toney Harber
</div>
</span>
</td>
I have tried with span tag but this also shows null.
I am providing you 2 options try both.
Option 1
Please try below. It will return you a list. Loop through it. If there is only one span then you can get the element and then get the attribute value.
driver.findElements(By.xpath("//span[#data-original-title]"))
Option 2
Instead of
driver.findElement(By.xpath("//*[#id='content']/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/table/tbody/tr[1]/td[2]/span/div/a"))
use findElements
driver.findElements(By.xpath("//*[#id='content']/div/div/div[1]/div/div[2]/div[2]/div/div[3]/div[1]/table/tbody/tr[1]/td[2]/span/div/a"))
It will return a list of web elements. Loop thorough it you might get more than one element.