Disabling an element in selenium webdriver - java

I am trying to count the number of rows in an HTML table using Selenium webdriver (Java.). The functionality is as below:
Text is iteratively entered into a search box from CSV file. Once, first text is entered and search results are displayed in HTML table, I have to count the rows in that HTML table.
The issue I am facing is that for every search text, the count of number of rows in HTML table displays same. I suspect that the rows are counted before the HTML table is refreshed for every search text and hence the count remains the same as the first text every time.
I guess the HTML table should be refreshed every time new text is entered in search box and then rows in table should be counted.
Can anyone suggest the possible solution to this issue?
Can I temporarily disable the HTML element of webpage till the new text from CSV file is entered?

As you cannot post your code
There is was a way but i am not how feasible it is for your problem
this can be achieved using java script
you can disable any element Using java script
Refer this for disabling
http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_select_disabled2
1) using javascript executor you can execute it in selenium.
If First method is failing to do so
try
2)Execute your javascript first then run your selenium code means make your selenium method depends on the javascript method.
Let me know if this works out.

Related

Trying to add data to boxes without the xpath, a tricky situation [SELENIUM & JAVA]

I am working on this grid, using SELENIUM & JAVA and chromedriver.
Take a look at this and it's behaviour (it is a .gif):
When i need to add a new row to that grid i have to click on
"ADD OPTION" and then a new row is inserted
The problem is that i do not understand how to pass a collection of values, i want to achieve this:
I want to pass a collection and my program should place them in the grid (2 values each row) without getting the xpath of every single box. I need to make it more efficient.
Example: i have this collection:
["fdfdfddf","989"; "RERE","6655"; "HEHE","554"; "TTER","89"]
I want my program to place them in the GRID.
Desired result:
The problem is that in my code i do need to know the xpath of each "box" of the grid in order to insert data.
This is my code to add data to the grid:
driver.findElement(By.id("add_new_option_button")).click(); //it clicks on "Add Option" button
driver.findElement(By.xpath("//*[#id=\"manage-options-panel\"]/table/tbody/tr[40]/td[3]/input")).sendKeys("fdfdfddf");
driver.findElement(By.xpath("//*[#id=\"manage-options-panel\"]/table/tbody/tr[40]/td[5]/input")).sendKeys("989");
driver.findElement(By.id("add_new_option_button")).click();
How can i fill in the boxes without knowing the xpath of every box?
I don't want to click on every box of each row to get the xpath, i need to find another fast solution.
This is how i get the xpath of every box:
You can solve this by using xpath like.
Xpath=//*[#type='text']//following::input
Here First target a element which is just before your input box then when you add any new box then the xpath will like
Xpath=//*[#type='text']//following::input[1]
Xpath=//*[#type='text']//following::input[2]
Xpath=//*[#type='text']//following::input[3]
Now you can run a loop or otherway and input value inside the box without taking different xpath

Unable to write X_path to get text from application related reports in application,

enter image description here
In that Image i have tried with xpath using contains also but here class is changing dynamically when ever i run script, i want to get text present in that report
You can try for absolute XPath in this case and storing all the <div> in a List<WebElement>, then selecting the element you want using list index coupled with getText() method to fetch the text.

Read a text and click on a particular row of a table using Selenium in Java

I am trying to read and click a value in a row (row width=85) of table using Selenium. So far I tried these two methods, but unable to locate value. I am attaching html code as image.
findElementByXpath("//table/tbody/tr[2]/td[2]");
findElementByXpath("//table[#width=\"85\"]/tbody/tr[2]/td[2]");
Any help, really appreciated.
Rely on the id attributes to get the table element and get the first td with width="85"inside:
findElementByXpath('//div[#id="Display"]/table[#id="tblData"]//td[#width="85"]')
Note that relying on the width attribute doesn't seem very reliable. Alternatively, use indexes - get the second td in the first tr tag inside the table (indexing starts from 1):
findElementByXpath('//div[#id="Display"]/table[#id="tblData"]//tr[1]/td[2]')

Selecting a WebElement With a Fluid ID?

I have an application which I am trying to test with WebDriver. On one page, the user selects a data source and some other options and then clicks next. When the user clicks next, they are presented with a page which has a list of documents that they must upload prior to submitting a request.
On the page with the documents that they must upload I am attempting to get the names of the documents and then compare them with a spreadsheet which has the list of required documents based on the data source the user chooses.
Here is my problem, I am trying to get the document names off the website. I first tried it with
String docOne = driver.findElement(By.xpath(/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div/div/h5)).getAttribute("textContent").toString();
System.out.println(docOne);
When I run this, it cannot find the element.
I then tried the following:
String docOne = driver.findElement(By.xpath("id('41027')/div[1]/h5")).getAttribute("textContent").toString();
System.out.println(docOne);
When I ran this, it could not find the element, I then manually tested this and found that every new request has a new ID, even though the first xpath I tested does not change.
My question then is, how do I get this to work? Since the element changes everytime I run the test?
I apparently had some brain flatulence this morning.
When automation clicks next to get to the documents page the page is scrolled all the way to the bottom and the top elements apparently cannot be found. I put a long delay 30 seconds and scrolled to the top of the page manually and the test passed with the first xpath I mentioned.
So I selected a web element which is always visible and told it to do a send keys with a page Up command, and it worked swimmingly.

Selenium - auto completion (prediction text)

I am new to selenium web driver.
When I try to auto-complete a particular text and select an option from the prediction text list as given below, it selects the appropriate option.
The problem is after the phrase gets populated in the text box, the prediction text list is displayed again, due to which it is unable to perform the next step.
I am using xpath to select the option from the prediction text list:
driver.findElement(By.xpath("//div[#class='mui-pt-bd']//li[2]")).click();
Please let me know what I can do regarding this.
Try adding some synchronization code to wait for the prediction list. After that call the click method. See http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp
First, make sure there are no trailing spaces for the prediction text that you chose by clicking from the list. If there are, it might trigger the prediction text list to open up again.
If this not the case, the only thing that I can think of is, clicking elsewhere within the same frame/form so that the prediction text list gets closed.
Another thought is that, after choosing one item, the usually expected behavior is for the drop-down to close. If that is not happening manually, then, you might want to make sure it is not a bug with the Application itself.

Categories

Resources