How can I select an XPath with multiple conditions - css

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.

Related

Why do I get different answers from css and xpath selectors?

I am trying to scrape the following link using scrapy. cpuc website document
There is a table on that page, the values of which I am trying to scrape. When I scrape using xpath, it gives the correct answer. eg response.xpath("//td[#class='ResultTitleTD']/text()").getall()
gives
['Comments filed by Southern California Gas Company on 06/24/2021 Conf# 167430', 'Proceeding: A2011004', 'Comments filed by Southern California Gas Company on 06/24/2021 Conf# 167430 (Certificate Of Service)', 'Proceeding: A2011004']
as expected but when I run response.css("td.ResultTitleTD::text").getall(), I get an empty list as answer.
Why are css and xpath selectors giving different answers for the same query?
You are trying to use invalid CSS locator.
You can use td.ResultTitleTD as a valid CSS selector, get those elements and then extract their texts but you can't use td.ResultTitleTD::text as CSS selector to access those lements texts directly.
UPD:
Here is the dev tools screenshot where I see those 2 elements located and highlighted using the above CSS selector

Is it possible to style an Entity Relation Diagram with Mermaid.js like Flowcharts to indicate a difference in entities?

I can't seem to style any elements within my ERD.
Having an entity called PERSON, any of the following code results in a syntax error:
style PERSON fill:#f9f;
or
classDef className fill:#f9f;
class PERSON className;
or
classDef default fill:#f9f;
Looking at the documentation, I should be able to use simple styling:
https://mermaid-js.github.io/mermaid/#/entityRelationshipDiagram?id=styling
Basically I'm trying to make a high level ERD where I need to mark certain entities to indicate a difference.
Any help or advice would be appreciated. :-)
I wasn't in luck either. In flowcharts it seems possible to style and shape the nodes though.
https://github.com/mermaid-js/mermaid/blob/develop/docs/examples.md
It's not currenly possible to style erDiagrams in Mermaid JS per github issue: https://github.com/mermaid-js/mermaid/issues/2673

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')]

Web Component Is there any paper-checklist-filtering available?

Hi guys I'm looking for a Polymer-type checklist filtering element: http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/functionality/filtering/checklist-filtering
There would be a list with checkboxes and maybe a select all item on top. And then there will be like a paper-input on top that allows filtering of items below.
I can hack together a checklist-filtering component using paper-input and iron-dropdown. Maybe I would make something like this https://github.com/samccone/paper-typeahead, assuming that nothing is available as of now.
No.
Most of existing and shared Custom Elements can be found at:
Component Kitchen
Custom Elements IO
There's also an alternate Material Design Library with elements that you could reuse to build your custom element :
ExpandJS

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