Need help locating element with XPath - xpath

I am learning about xpath , can you help me go to the "i class" tag and click on reddit's up vote icon. I tried to find the comment text
I can connect the paragraph
//div[contains(p/text(),'The user name completes this')]
and find the up vote icon tag right below this comment
https://www.reddit.com/r/me_irl/comments/zg7nr5/comment/izgy4a3/?utm_source=reddit&utm_medium=web2x&context=3

You can locate the parent div block of the entire comment by the text content and then go to upvote button inside it as following:
"//div[contains(.,'The user name completes this')][contains(#class,'Comment')]//button[#aria-label='upvote']"
I'm not sure you really need that i icon element so I gave the locator of the upvote button.
In case you really need the i element inside it - it can be located similarly as following
"//div[contains(.,'The user name completes this')][contains(#class,'Comment')]//i[contains(#class,'upvote')]"

Like this:
//div[contains(.,'The user name completes this')]//button[#data-click-id='upvote']

Related

Robotframework xpath how to locate element

I want to click on this element:
<a id="welcome" class="panelTrigger" href="#">Welcome Admin</a>
but I am not able to locate this element.
I have tried:
id=welcome, xpath=//*[#id="welcome"]
Click Element or Click Link but it is not working. Can you please help me?
I think you should be fine any of the lines below:
Click Link id:welcome
Click Link Welcome Admin
Based on the documentation:
When using the default locator strategy, links are searched using
id, name, href and the link text.
So if the ID does not happens to be unique you can still refer to the link by its text.
Try this way
Scroll To Element xpath ${element_locator}
Wait Until Element Is Visible ${element_locator} timeout=30s
Click Element ${element_locator}

find element by xpath 'No such element' error

Can someone tell me why im not able to access the "select" xpath? I'm getting "No such element exist" error. The website link is: https://www2.fdic.gov/sdi/main3.asp?cert=26486&repdte=MostCurrent. I'm using selenium webdriver.
select=driver.find_element_by_xpath('/html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr/td/select')
Try
select=driver.findElement(By.xpath('//form/table[2]/tbody/tr/td[2]/table/tbody/tr/td/select'))
In the beginning of xpath you use '//' and not need 'html/body'
I agree with #Marc B above. The select element is inside a frame, hence unless you switch to the frame, your code won't work.
1- First, Switch to frame using the below code (multiple ways are there, this is one of them):
driver.switch_to_frame("content") //Found that the select tag is under frame with name "content"
2- Then, use your code or the code below for the select element:
select=driver.find_element_by_xpath('//select[#name='selColumnType2']')
3- After your task with the frame is over, use the below code to switch back to main window and proceed further:
driver.switch_to_default_content()

Tumblr: how do I remove the description/sidebar box on the submit page in the default Peter Vidani theme?

I have a tumblr account that has submission enabled, and I have a short description with a form in the "description" area that appears on the sidebar. However, this description also appears on myblog.tumblr.com/submit. I'd like to remove it.
I looked at the documentation on http://www.tumblr.com/docs/en/custom_themes#navigation, but haven't been able to figure out how to prevent the sidebar description from showing at the top of the submit page.
Can anyone help?
I'm not sure if I understood your question correctly. But if I did, a work around would be using jQuery to check if the current url contains the string /submit and simply disable the sidebar, or the element that contains the description.
I don't know jQuery but I know it's possible. I'd suggest you to look into this post:
How to check if the URL contains a given string?
and combine it with this line (replace the "alert part")
$("#sidebardescription).hide();
Another solution would be if Tumblr provided you with a way to only render for specific pages. They usually do that. I'd look into this part {block:SubmissionsEnabled} {/block:SubmissionsEnabled} before I go with the workaround.

How to show a module in Joomla when it's not a Menu item

I am trying to show a module, but the article I want to show the module on is not linked to a menu item. Is this possible? Seems like a module can only show when it is a menu item. But I have a ton of articles that are not menu items - so what is easiest way to show the module? Any help would be greatly appreciated.
The way to do this is as follows.
Let's suppose you have a group of articles that you wish to all display the same modules on.
Create a new category using the "category manager" option from the content menu
Ensure all the articles are published into this same category.
Create a new menu which you won't actually ever display anywhere (I like to publish the menu into a module position which is not present in the template)
Add a category blog layout option to this new menu
Now go through each of the modules that you wish to display for the group and add them to the new menu item you have created.
Hope this helps!
This will be my first answer after getting so many help through stackoverflow without being a member.
I will just add something to buzzki's answer. Because i was almost loosing my mind until i figure out how to solve.
If you used an article in a module with an extension like mod_articleasmodule; it adds the aliases of articles on URL of Read More.
Simply change the line;
$link = "index.php?option=com_content&view=article&id=".$item->id.":".$item->alias."&catid=".$item->catid.":".$item->catalias;
to
$link = "index.php?option=com_content&view=article&id=".$item->id."&catid=".$item->catid;
to get the pure URL Link and your menu assigned by MetaMod will work. Also great thanks to buzzki for help.
While the {loadposition xxx} technique is very handy, what it won't do is to put the module into any of the "standard" module positions (e.g. left, right, banner, or whatever your template has).
If you want your module in one of those positions, a great method is to use MetaMod. MetaMod is a placeholder module, that includes other modules inside of itself according to rules that you set up.
So you can set it up with a rule that says, in effect, "if we are on article A, B, C, D or E, display the module".
if ($content_genius->check("article_id = 50, 51, 52, 53, 54")) return XXX;
// replace XXX with the module id to show on those articles
Now, if the number of articles is going to change regularly, you don't want to have to edit the MetaMod to change the list of ids. So another way is to use the Meta Keywords field in the articles to determine whether the module will appear. Then all you have to do is include that keyword on any article you want the module to appear on. Let's say the keyword will be "SHOWMOD".
So in MetaMod you can simply use this:
if ($content_genius->check("article_metakeywords contains SHOWMOD")) return XXX;
// replace XXX with the module id to show on those articles
In that way, the module will appear on every article page where the article contains that meta keyword. And the module position can be any position on the page (wherever the MetaMod is assigned).
Step 1: On the front end of your website, click to the specific article that you want, highlight and copy the URL.
Step 2: Create a menu item, item type is URL and paste your article URL in there. (You can have the menu item be in an unpublished menu i think)
Step 3: Select it from the Menu Items list in the module.
You simply name your module position whatever you want, say 'monkey' where your module offers a 'select position'. You actually type it in. Then in the article you want to place it in, you add
{loadposition monkey}
to any location of your article you want the mod to work in the html editor.
Follow these steps in your joomla site Admin panel:
Go to the module manager, open the desired module and give a unique name in the position field. If you want to use it also at other common position such as left or right, then first create a copy of this module and then for the new copy, create a unique position name. Example: custom1.
Create a new article preferably uncategorized. Give it the name of your module.
In the body area of the article type {loadposition custom1} and save your article.
Create a Menu link to this article in the desired menu. You should select 'Article layout.'
Thats all, your module will now load from the menu link directly.
This has an added advantage of giving you SEO prominance based on the meta info you give for this article.

XPath Expression

I am new to XPath. I have a html source of the webpage
http://london.craigslist.co.uk/com/1233708939.html
Now I want to extract the following data from the above page
Full Date
Email - just below the date
I also want to find the existence of the button "Reply to this post" on the page
http://sfbay.craigslist.org/sfc/w4w/1391399758.html
Can anyone help me in writing the three XPath expressions for the above three data.
You don't need to write these yourself, or even figure them out yourself. If you use the Firebug plugin, go to the page, right click on the elements you want, click 'Inspect element' and Firebug will popup the HTML in a viewer at the bottom of your browser. Right click on the desired element in the HTML viewer and click on 'Copy XPath'.
That said, the XPath expression you're looking for (for #3) is:
/html/body/div[4]/form/button
...obtained via the method described above.
I noticed that the DTD is HTML 4/01 Transitional and not XHTML for the first link, so there's no guarantee that this is a valid XML document, and it may not be loaded correctly by an XML parser. In fact, I see several tags that aren't properly closed (i.e. <hr>, etc)
I don't know the first one off hand, and the third one was just answered by Alex, but the second one is /html/body/a[0].
As of your first page it's just impossible to do because this is not the way xpath works. In order for an xpath expression to select something that "something" must be a node (ie an element)
The second page is fairly easy, but you need an "id" attribute in order to do that (or anything that can make sure your button is unique). For example if you are sure the text "Reply to this post" correctly identify the button just do it with
//button["Reply to this post"]

Resources