I am trying to navigate a website that stores documents related to several projects. To get to a specific project I need to search a project name by inputting it in the search bar and selecting from the search result. I am able to find the search bar and search for the project that I am interested in but, trying to click on the searched project gives me "element is not visible" exception.
There is also a recently viewed projects section and I can select every project in this list except the first one. This does not help my use case though as the project, that I am searching for, might not always be in the recently viewed list. And I cannot select the first project in this list (But that is a different question maybe for some other time)
Here is the python code that I am using
change_proj = find_element.ret_element_handle(browser, 'xpath', '//td/em/button[text()="Change project"]')
change_proj.click()
print("after change_proj")
# Search bar in pop up window to change project
search_bar = browser.find_elements_by_name("searchString")
search_bar[1].send_keys(projectName)
project = browser.find_element_by_xpath("//span[contains(., '" + projectName + "')]")
project.click()
# This is the line that generates the exception
With the great help available on internet, I have tried a) waiting for element to be clickable, b) moving to the element "project" using ActionChains c) trying different version of the xpath that looks for a specific text but, none of these have worked.
I am attaching the html of the page as the image (Some entries are blanked out for confidentiality)
Related
I would like to know how I could program in VBA using Selenium to click/choose on website the first autosuggestion, for example as you can see in the screenshot from amazon.es
Do you have any suggestions?
Tom
Since your situation is replicable I managed to test this two (2) approaches to your situation. I'll just remind you that is always good to show us some code you've tried in your question, so it does not feel like we are helping you from scratch, also try not to rely on images to show us your situation, unless is something that does not change much «like in this case, Amazon.es page». That reminded, let's go to the good part:
1) Advanced 1:
a. Spaces in class are change for dots (if there is any)
b. Requires to understand tag's meaning (a tag is like an object)
'Example
'Clicking first element under tag ("div" alone is a tag)
Selenium.FindElementByCss("div.autocomplete-results-container > div").Click
2) Advanced 2:
a. Requires to understand what ":nth-child" (CSS selector) is
'Example:
'Clicking first child of "div" (Everything inside "div" is a child - starts in 1)
Selenium.FindElementByCss("div.autocomplete-results-container > div:nth-child(1)").Click
I used Firefox to get the xPath property of that suggestion made by the web page. To quickly compare, I copied and pasted, one at a time, the xPath of the first 3 suggestions shown:
/html/body/div[1]/header/div/div[2]/div/div[2]/div[1]/div/div[1]/span[1]
/html/body/div[1]/header/div/div[2]/div/div[2]/div[2]/div/div[1]/span[1]
/html/body/div[1]/header/div/div[2]/div/div[2]/div[3]/div/div[1]/span[1]
So, for the first item, just use the first xPath. If you want to select, for example, the second, just vary the index of the sixth DIV, as we can see in the samples above. Assuming you already have part of the code that navigates to the page, use this, adapting the name of the WebDriver:
objSeleniumDriver.FindElementByXPath("/html/body/div[1]/header/div/div[2]/div/div[2]/div[1]/div/div[1]/span[1]"). click
I am new to XWiki and not a Java Developer. I would like to develop a simple AppWithinMinutes app (Let us call it ServerCatalog) for a list of servers with their properties like OS, Environment, etc.. That is all doable. I can develop that from AppWithinMinites UI.
I also have developed a macro which lists all pages by tags.
Now for example, when Someone creates an entry in my ServerCatalog say SERVERD56 Where D stands for Development environment.
when we display that Entry, I also want to execute my macro that I developed so that it can list all pages that matches the tag SERVERX56.
Note that I replaced D with X So before executing macro, I want to manipulate that page title and remove Environment prefix (in this case D for Development Environment) with X.
I hope it is clear of what I want to accomplish. Please let me know if it is unclear.
If someone can assist me on doing it, I will truly appreciate that.
EDITS:
As suggested by Eduard Moraru, I tried following things:
I have created a custom macro called "PageListByTag".
Since python has more control over string operations, I added following at the end of ServerCatalogSheet
.
.
.
.
{{/html}}
{{/velocity}}
{{python}}
title = document.getTitle()
newTitle = title[:6] + "X" + title[6+1:]
print(newTitle)
{{/python}}
There are several problems with it..
my html tag is already ended. I can't inject any new content in it anymore
I can't add python code inside velocity tags as nested scripting is not allowed by XWiki
I still don't know how to call my macro inside python code if I want to use python
If I can replace 6th character in a string using velocity, then everything works. I can use macro inside velocity script since it is within that html boundaries.
As far as I understand, you want to customize the "sheet" of the application which is used when displaying an application entry.
If you have a look a the documentation's section on customization, you get a lot of starting points on where you should be looking:
https://extensions.xwiki.org/xwiki/bin/view/Extension/App%20Within%20Minutes%20Application#HCustomization
This line would be interesting (but also the above links on how XWiki applications work):
The sheet, which is used to display and edit application entries (e.g. HolidaySheet)
In your case, it the document to customize (edit in wiki syntax mode) should be ServerCatalog.Code.ServerCatalogSheet
Inside that document, you have code automatically generated by AWM to which you can add a call to your macro.
## AWM generated code...
...
## Customization:
{{displayAssociatedPages /}}
Then, inside this macro (called displayAssociatedPages, in this example), you could do something like:
{{velocity}}
#set ($title = $doc.title)
## OR #set ($title = $doc.name), depending if your pages have titles
#if ($title.startsWith('SERVERD'))
#set ($tag = $title.replaceFirst('SERVERD', 'SERVERX'))
##
## We can reuse and customize this snippet: https://snippets.xwiki.org/xwiki/bin/view/Extension/Display%20pages%20with%20a%20specific%20tag/
##
#set ($references = $xwiki.tag.getDocumentsWithTag($tag))
#foreach($reference in $references)
#set ($document = $xwiki.getDocument($reference))
#set ($label = $document.getTitle())
[[$label>>$reference]]
#end
#end
{{/velocity}}
API documentation and more info at https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/API/
Also, you should understand that once you customize an AWM application, you should be careful when editing it with AWM itself. For example, if you add a new field, AFAIK, you risk having the customizations done to your sheet, as in the above example, overwritten, so you should recover them from document history and re-apply them.
I am trying to copy the text highlighted in Yellow (from the HTML image) using a Selenium VBA code with MS Excel to a string. However, it is crashing and not getting copied. But the same code is working if I were to use it on other websites where the division does not contain "Data-Role" element within a webpage. I tried to make use of all element type like ByName ById ByClass but none of these technique seems to be working. Please note I am using Selenium to access the Chrome browser. I am trying to store the Yellow highlighted text data into a string "Res". Any help or tip is much appreciated. Below is the sample code which I am trying to use.
Dim Res As String
Dim be As New WebDriver
On Error Resume Next
be.Start "chrome", ""
be.Get "the website from which I am tryig to pull data"
Res = be.FindElementByClass("text--1jzYQ uppercase--tL_HU").Text
[![enter image description here][2]][2]
Without having the website address (if able to test with it), or any error messages, can't tell you why it is crashing. Possibly accessing a dynamic element which is still resolving? Dunno.
However, those classes look dynamic, so in terms of robustness, perhaps try using a combination of more stable looking attribute = value css selectors:
be.FindElementByCss("[data-role=status-bar] [data-role=status-text]").text
I've done some looking around in here and on the internet and it doesnt seem super obvious, but my question is can python using tkinter be used to automatically convert a text string into a link that loads a pdf from a certain direction
e.g. data '12345 Issue A' pops up in a text widget and is automatically converted to a link that when clicked opens up a pdf document.
Can this or can it not be done ?
In this case I'm wanting to be able to click 1931-125, 699-126 and 1851-127 and have each open up a pdf file of the same name. This is being used in a manufacturing environment and allows an assembler to click the fields and have all the documents they need to build a certain item
First off to apply formatting to parts of a Text widget you will need to understand about tags, in most cases you can probably just use the phrase of the link (ABC123) just remember that:
The name of a tag can be any string that does not contain white space or periods.
once you have a tag for the link there are two parts:
Formatting the tag to look and react like a link.
Applying the tag to the phrases in text.
The first one is really simple if you just want it to be blue and underlined and respond to being clicked:
def format_link(text_widget,tag,command):
text_widget.tag_config(tag,foreground="blue",underline=1)
text_widget.tag_bind(tag,"<Button-1>",command)#remember that the command will need to take an event argument
Although this could get more complicated if you want the cursor to change when hovering over or colour to change after clicking etc.
The second part is to apply this tag to the text automatically which I'm assuming means parse the text after it is inserted into the widget. This is also very simple by putting this answer in a loop so that it checks for every occurrence of the phrase:
def apply_tag(text_widget,phrase,tag,regexp=False):
countVar = tk.IntVar(text_widge)
idx = "1.0"
while idx:
idx = text_widget.search(phrase,idx, stopindex = "end",
count = countVar, regexp = regexp)
if idx:
end_idx = "%s + %sc" %(idx, countVar.get())
text_widget.tag_add(tag, idx, end_idx)
idx = end_idx
Then all that is left is defining the way to open the file in another program and then calling the two above functions, using os.system("open"...) to open files it could be as simple as:
def make_link(text,phrase,file_to_open):
def callback(event=None):
os.system("open %r"%file_to_open)#there are better ways of handling this
apply_tag(text,phrase,phrase)#uses phrase as tag
format_link(text,phrase,callback)
Although you might want to look at answers here or it's duplicate for alternatives for opening files.
after inserting the text into the widget, assuming you have some sort of list of phrases to turn into links, you can just loop over the phrases and call make_link for each one:
phrases = {"1931-125", "699-126", "1851-127"}
for s in phrases:
make_link(TEXT_W, s, s+".pdf") #make a link to same name with .pdf added to end.
I am working with typo3 4.7 and trying to redirect the search results of the indexed search plugin to a page in my site and managed to stumble upon the constants editor where I've managed to use it to guide me in setting up the object. Below is the current typoscript of the object in my root template (mapped into a TV template):
# --- SEARCHBOX OBJECT ----------------------------------
lib.searchbox < plugin.tx_indexedsearch
lib.searchbox{
#Disable the advanced search link
show.advancedSearchLink = 0
show.rules = 0
show.alwaysShowPageLinks = 1
#pid of root page is 1 and pid of the search result page is 9
search.rootPidList = 1
search.targetPid = 1
view.defaultPid = 9
result_link_target = 9
}
Thus far I have been unsuccessful in my attempts and all results are displayed in the page in where the search was performed. I would also like to know if it is possible to modify the displayed search box so that only the search field is displayed.
Thanks for your time.
Edit: I have installed and I'm trying out solr, if anyone has any experience with it pls feel free to help resolve this issue. My two problems with solr so far is that whilst search does re-direct to the right page, (1) the search box is way too big so I need to be able to modify the display of this box (to remove the button and reduce the size) (2) it spouts som e messages about search rules and returns nothing so far.
Edit 2: Seems solr is the way forward. I have managed to get everything I want done except the result output. I lost a few days (5) before realising that the tomcat container was bound to an ipv6 protocol interface. Resolving that (see here for those who may stumble upon the same problem for how to resolve this) has meant I can now remotely admin the solr server for more information. The pages are being indexed (Not regularly as specified in the scheduler) but I still get no results on the result page, and devlog only returns warning about there not being typo3 search markers despite my TV templates being peppered with them. I can only guess that maybe I'm to mark the results page with some type of marker to get the results to show at this point.
plugin.tx_indexedsearch {
search {
targetPid >
targetPid = 123
}
}
Reference: http://lists.typo3.org/pipermail/typo3-team-core/2010-March/036269.html
Experience: works even in TYPO3 version 6.x.
Default setting for plugin.tx_indexedsearch.search.targetPid is:
plugin.tx_indexedsearch {
search {
# TSFE:id is always the current page
targetPid.data = TSFE:id
}
}
I have never used the indexedsearch plugin as the searchbox on all of my pages.
Normally, I do this
Create a page with the indexed_search plugin as its content, this is
where all search requests are answered
Use macina_searchbox to
display a search box as part of the template
To elaborate:
Install macina_searchbox, and use this Typoscript to configure it
plugin.tx_macinasearchbox_pi1 {
pidSearchpage = {PID_OF_SEARCH_RESULT_PAGE}
templateFile = {PATH_TO_TEMPLATE_FILE_FOR_SEARCH_BOX}
}
Then, include macina_searchbox like so
lib.searchbox < plugin.tx_macinasearchbox_pi1
The search result page just needs the indexed_search plugin where you want the results to be displayed.
I would just create a search box, copy the HTML-Code, adjust action-url and HTML-Code and output it. IMHO there is no need, to render it via Plugin, if you just need an search-input field and an button. But do not forget the hidden fields!