Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
driver.findElement(By.xpath("//*[#id=\"__box23-arrow\"]")).click();dropdown
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
Thread.sleep(5000);
driver.findElement(By.xpath("//*[#id=\"__item1283-__box23-2\"]")).click();
Every time my xpath changes //*[#id=\"__box23-arrow\ example //*[#id=\"__box24-arrow\, im doing automation for SAP, Can you please give any other solution
If your xpath will always be changing, to get your Selenium code to work atleast there should be some pattern in how it changes, for example it may be dependent on current date. Then you can code accordingly to generate your xpath dynamically every time you run your script. If there is no such pattern and no static content to be able to use contains in xpath, you should check out other tools like Sikuli. It uses image recognition to identify your element. This again assumes that the visible aspect of your element remains same.
There is also a wave of new testing products powered by AI like Testim which are "self healing", meaning they will adapt to changes in the source code. I haven't used them but they are probably what you want.
If you know the beginning of your id which is static throughout in that case you can go for
"//*[#id*='__box']"
This will give you element(s) whose id starts with '__box'
Hope this helps!
You can write dynamic xpath using contains keyword as well.
Please refer example below -
//a[contains(#id, 'ctl00_btnAircraftMapCell')
As per the HTML you have shared with us , You can try with this xpath :
//span[#role='button' and contains(#class,'sapMComboBoxArrow sapMComboBoxBaseArrow sapMComboBoxTextFieldArrow')]
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to change my DOM tree by removing all nodes except some.
For example, if I want my new DOM to have one of the leaf nodes of the old one, everything needs to be deleted expect the leaf and everyone of his parents (ancestors). Basically I have a list of nodes at some depth that need to be saved and everything else removed.
Iterating on every level to remove nodes takes to much time. I also tried approaching this using "ancestor-or-self" with xpath but that's not helping me delete nodes.
XSLT is designed for this job; it can be called from Java, and it can operate on DOM trees. Basically the rules you outline in your question translate directly into template rules in XSLT, but to give you examples I would need a more precise specification.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have been learning how to build android apps this summer. I am currently trying to work on xml parsing which falls under java in this case. I have a few questions that are mostly conceptual and one specific one.
First, in most of the examples I have seen pages already in xml are used. Can I use a page in regular html format and with whatever the program does turn it to xml and then parse it? Or is that what is normally done anyway?
Secondly, I could use a little explanation on how the parser actually works and saves the data so I will better know how to use it (extract it from whatever it is saved in), when the parsing is done.
So for my specific example I am trying to work with some weather data from the NWS. My program will take the data from this page, and after some user input take you to a page like this, which sometimes will have various alerts. I want to select certain ones. This is what I could use help with. I haven't really coded anything on that yet because I don't know what I am doing.
If I need to clarify or rephrase anything in here I am happy too and let me know. I am trying to be a good contributor on here!
Yes you can parse HTML and there are many parsers available too, there is a question about it here Parse HTML in Android, then we have an answer here about parsing html https://stackoverflow.com/a/7114346/826657
Although its a bad idea, as the tag names aren't well named, so you will have to write lots of code searching attributes for a specific data tag, so you always have to prefer XML,for saving lots of code space and also time.
Here is a text from CodingHorror which says at general parsing html is a bad idea.
http://www.codinghorror.com/blog/2009/11/parsing-html-the-cthulhu-way.html
Here is something which explains parsing an XML document using XML PullParser http://www.ibm.com/developerworks/library/x-android/
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to start from a given file(i.e. a.html) and if I see a pattern as like that:
<!--$include file="b.html"-->
I will go that file(b.html) and take whatever it has and all files will be written as into a final file(i.e. output.html)
If I see an include at b.html I should follow that include too and take whatever it has and I should repeat it recursively at Java?
Any ideas?
PS: It is similar to what jsp:include does but I want to implement it myself. I will implement it as a Maven plugin and I constructed a maven plugin for my need however using recursion or not and using a regex pattern or any other efficient way is what I am looking for.
You need to create a function to get files list, e.g. getFileList(htmlFile:File): File[];
Create a readline function and create a function to parse line which pattern is like "^.*<!\\-\\-\\$include file\\=\"(.+)\\.(html|htm)\" \\-\\->.*$", this is a regular expression, it can match what your searched regex. let's defined the function's name as checkRule(line:String):boolean
If checkRule return true, and get file name, then recursively invoke getFileList by passing just found file name.
Be careful about infinite loop. For example, a.html includes b.html, and b.html includes a.html, it would become infinite loop. So you need to check file list to ignore the file.
Good luck!!!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm doing an algorithm to classify the relevance of a page for some theme like 'movies' using all meta information as possible, but excluding the textual content of the body.
I want to know what can I use to determine if a page has some info about the theme.
At the moment, I'm giving an importance of 40% for the title, 30% for the link after the domain, 20% for the domain and 10% for the meta keywords, but I think I can use more thing to be more precise. I'm matching some words with some weighting to calculate the relevance of the page.
Any ideas of what more can I use to calculate the relevance? I only want to exclude the text-content inside HTML itself, but the HTML structure can be used.
I think you should think about the Main Menu links , and if is the case a Submenu links , so to make it more simple , LINKS . And you should also take in count the metadata . But still i em not sure what are you trying to achieve .
From what i understood you are trying to make some "relevancy" formula for a webpage .
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am working on a basic instant search function that basically searches the database and displays the results instantly just like google instant. This here http://woorkup.com/2010/09/13/how-to-create-your-own-instant-search/ looks promising but I want to know if there is a way to implement this using JSP, java/servlets.
Java and servlets alone will not be sufficient, you will need JavaScript on the client side. Basically you attach a listener to the input field and send an AJAX request to a JSP that does the search and returns the results which you then only have to format and display in a drop-down box below the input field.
This is also a very good tutorial about instant search:
http://www.w3schools.com/php/php_ajax_livesearch.asp
It uses Java Script and PHP. By reading / doing this tutorial you should get a idea how instant search works. So I hope this helps even if you want to use JSP.
You can do this using jQuery. The jQuery UI autocomplete is nice and easy to implement:
http://jqueryui.com/demos/autocomplete/
As previous posters have pointed out, you will have to use JavaScript to do this. The least painful way to use JavaScript here is to use JQuery UI
There is a fairly straightforward walkthrough here: http://blog.comperiosearch.com/2012/06/make-an-instant-search-application-using-json-ajax-and-jquery/
This is an oldie-but-goodie:
http://lab.abhinayrathore.com/autocomplete/
Combines Google,Bing,Yahoo,Wiki,Amazon, etc. all in 1 instant autocomplete. Allows you to easily add/remove websites.