How can I find a link by URL in my functional test? - symfony

In the Symfony testing documentation, it shows how to select a link containing specific text:
$crawler->selectLink('Click here');
But the link I'm looking for won't always have the same text. It will say one of a few different things depending on the status of the record, so instead, I need to find it by URL. I think I can figure out how to do it using an xpath filter. Is that what I should go for, or is there a better way?

You would be testing against a known state - and so that state will inform what text should be on the button.
If not - you can also search by a CSS ID, or enough other information to uniquely identify the button, such as a class name of a button within a range specified by an ID, with a CSS Path, or XPath.
Full CSS Path to the `<code>` block in your question
#question > table > tbody > tr:nth-child(1) > td.postcell > div > div.post-text > pre > code
Xpath
//*[#id="question"]/table/tbody/tr[1]/td[2]/div/div[1]/pre/code
A specific ID, or the text to look for would be a lot easier though, and far less likely to break!

Related

How can I select an XPath with multiple conditions

From this website, I want to get all genres in the Genres & Subgenres menu using the selenium framework. For that, I need a general xpath or css selector that applies to all of them. I have noticed that all genres have "genreid:D+++" as a part of their id and are located in tag. How can I use this information to get all genres? If you know a better way to solve my problem please write it.
https://www.allmovie.com/advanced-search
Xpath for all Genres & Subgenres
//input[contains(#id,'genreid')]
I'm more familiar with CSS than XPath so I will answer that part of your question.
To make a CSS selection for an element ID that starts with genreid, you'd use this selector:
[id^=genreid]
That will give you the checkboxes. If you wanted the <li> elements that contain them, you could just select by the classname: .genre
For more info about CSS selection, see MDN's great documentation here.

What is the best way to customize the design/skin of mediawiki?

I'm new to mediawiki and want to make my own skin for a mediawiki. For example I have a button (div.button-field > input) and I want to give it height: 100%. I know you can put it in a custom.css like
div.button-field > input {height: 100%;}
But if I do it for every element I want to customize the .css gets very long. The other thing, if I want only to customize a specific button which is nested like "div > div.container > form > div > div.button-field > input" and I add a div or remove a div, then it wont work anymore and I have to adjust the "path". So what would be the right way todo it? Or is the .css the best way todo it?
With kind regards
Oli
The answers depend on how much you want to change.
The first easiest path is to find an existing skin, see on MediaWiki.org.
You can configure some elements like the logo, the favicon or the sidebar, and you can change every text message of the interface.
Then, you can customise, as a logged-in administrator, the CSS rules by modifying the page MediaWiki:Common.css (example on English Wikipedia), or possibly MediaWiki:YourSkinName.css for skin-specific rules (for example MediaWiki:Vector.css to modify only the skin Vector; example on English Wikipedia).
You can also modify add JavaScript features by modifying MediaWiki:Common.js (example on English Wikipedia), or MediaWiki:YourSkinName.js for skin-specific rules (for example MediaWiki:Vector.js to modify only the skin Vector; the page does not exist on the English Wikipedia).
This kind of modification is recommended because it will be kept during MediaWiki updates, although minor adaptations could be needed on the long term.
If you want heavier changes, you can copy an existing skin, rename it, and change the PHP code, for instance by moving or deleting entire blocks. Prefer copying a well-supported skin like Vector or Monobook to be sure it is compatible with most MediaWiki extensions.
But it will take some or lot of work during MediaWiki updates (depends on the quantity of changes), and if you cannot do this work the risk is either you custom skin breaks or you will stay with an old MediaWiki version (which is not recommended for security reasons).
Also, if you choose this path, be warn not to break the structure expected by the VisualEditor if you want it continues to work.
There is a tutorial on MediaWiki.org to adapt the skinning from easiest ways to heaviest, see Manual:Skinning Part 1 and next pages.

css message locator in robotframework

Please advice me about to find css message locator in robotframework.
I can not use id cause of change every time when I run test script.
Only Class not change but have a lot of message.
Hence I want to catch the message instead.
enter image description here
enter image description here
As far as I could understand, you need to select an element based on CSS class. If you need exactly that solution, you can go with CSS locator css:z-menu-img, if you are sure that this is the only element with that CSS class in the page.
Otherwise, I propose another solution (as unstable as the others because it can change over time): use XPath. For your case, it can be: //*[#id="kOIQf6-a"]/span.

How to click on a link based on text in a table using selenium

Hi All,
I have the following table with links that I need to select. In this specific example I need to select the DIY Payroll but sometimes this can change its position within the table. The current xpath is:
.//*[#id='catalog-category-div-1']/table/tbody/tr/td1/ul/li[4]/a
So I do a:
By.xpath(".//*[#id='catalog-category-div-1']/table/tbody/tr/td[1]/ul/li[4]/a").click()
But the problem is here is that it can change position where it can be in td[2] or td[3] and li[n'th postion]
Can I have selenium go through the table and click on it based on text. Will the By.linktext() work here ?
You can use the following codes these codes will handle the dynamic changes.
You can use linkText() method as follows:
driver.findElement(By.linkText("DIY Payroll")).click();
If you want to use xpath then you can use following code.
driver.findElement(By.xpath(.//a[contains(text(),'DIY Payroll')).click();
If you need any more clarification you are welcome :)
I would suggest that you try By.linkText() or By.partialLinkText(). It will locate an A tag that contains the desired text.
driver.findElement(By.linkText("DIY Payroll")).click();
A couple issues you might run into:
The link text may exist more than once on the page. In this case, find an element that's easy to find (e.g. by id) that is a parent of only the link you want and then search from that element.
driver.findElement(By.id("someId")).findElement(By.linkText("DIY Payroll")).click();
The A tag may contain extra spaces, other characters, be capitalized, etc. In these case, you'll just have to try using .partialLinkText() or trial and error.
In some cases I've seen a link that isn't an A tag or contains additional tags inside. In this case, you're going to have to find another method to locate the text like XPath.
You should use a CSS selector for this case:
Can you try:
By.CssSelector("a.browse-catalog-categories-link")
You can use XPath to do this. //a will select all 'a' tags. The part inside of the square brackets will select everything with text "DIY Payroll". Combined together you get the desired solution.
//a[contains(text(),'DIY Payroll')]

Selenium: css query regarding get_attribute() function

I am trying to find the attribute value of the title attribute.
Now, I have a list of similar links on the same page and I want to select the first link and get its title attribute.
I have used the following selenium command:
self.se.get_attribute("css=a[href*='radio?rid=']:nth-of-type(1)#title")
But it is giving me an error.
Could someone please help me figure out the problem?
Thanks
You should use XPath syntax instead of CSS selectors. You didn't post any HTML to match, so therefore a made up example: to get the title of the first link found in a div with id myDiv, use the following:
self.se.get_attribute("xpath=//div[#id='myDiv']//a[1]#title")
Where:
//div[#id='myDiv'] matches any div with id "myDiv";
//a[1] select the first link found anywhere in the previously selected div (use 2 for the second, and so on.
#title specifies the attribute you want to retrieve.

Resources