Polymer 2 Nested ShadowRoots - polymer-2.x

I have a Polymer 2 component that is a parent to multiple Polymer 2 components, each component has it's own shadowRoot.
From the parent component, is it possible to query a node in one of the nested shadowRoots?
I believe you can't have element > shadowRoot > shadowRoot but my dom looks like element > shadowRoot > element > shadowRoot...
I've tried this.shadowRoot.querySelector('id') where id is the id of the element (in the nested shadowRoots) that I'm trying to query.

Related

Get child element from complicated xpath

So I have some complicated situation in the DOM where I need to create XPath and get its child element. I have the following XPath
((//p[contains(text(),'" + read_contract_title() + "')]/parent::div/parent::div)[2]//button)[2]
The above is basically a ... more options button, that I need to click and then click the child element inside of it.
How do I get about getting the child element (button) inside the above XPath?
Looking forward to your help and reply.
In case parent element can be located with this XPath
"((//p[contains(text(),'" + read_contract_title() + "')]/parent::div/parent::div)[2]//button)[2]"
The button element inside it could be simply located with
"((//p[contains(text(),'" + read_contract_title() + "')]/parent::div/parent::div)[2]//button)[2]//button"
In case this is the only button element inside that parent element

Selenium. child xpath selector as as pointer to parent element

So let's say my html structure have couple of similar div elements.
body/div/...
body/div/...
body/div/...
body/DIV/div[#class='class']
I would like to access the last one. But the one that is upper-cased.
So "//body/div/" selector will find many, but not related elements.
And "//div/div[#class='class']" will select the child div, not the upper case parent.
Use parent to select the parent of a given element:
//div/div[#class='class']/parent
If you want to be more verbose, you can also select a parent by a given tag name:
//div/div[#class='class']/parent::div

Accessing nested child components in VueJS

Using v2.2.2. I have the following structure in my VueJS app. How can I access all of the Account components from a method on my Post component? The number of Accounts is dynamic - I want to grab all of the loaded Account components and iterate over them.
I know it's got something to do with $refs and $children, I just can't seem to figure out the right path.
<Root>
<Post>
<AccountSelector>
<Account ref="anAccount"></Account>
<Account ref="anAccount"></Account>
<Account ref="anAccount"></Account>
</AccountSelector>
</Post>
</Root>
https://v2.vuejs.org/v2/guide/components.html#Child-Component-Refs
Despite the existence of props and events, sometimes you might still need to directly access a child component in JavaScript. To achieve this you have to assign a reference ID to the child component using ref. For example:
<div id="parent">
<user-profile ref="profile"></user-profile>
</div>
var parent = new Vue({ el: '#parent' })
// access child component instance
var child = parent.$refs.profile
When ref is used together with v-for, the ref you get will be an array
or an object containing the child components mirroring the data
source.
Basically inside AccountSelector.vue you can do this.$refs.anAccount.map(account => doThingToAccount(account))
Edit
The above answer is for accessing a direct child.
Currently there is no way to access a non direct parent / child component with $refs. The best way to get access to their data would be through events https://v2.vuejs.org/v2/guide/components.html#Non-Parent-Child-Communication or by using Vuex (Which i would recommend).
Non direct parent - child communication is very tricky without 1 of these 2 methods.
You can access nested components data using $refs and if you want to access the refs inside of it you first have to target the first element of the first refs ([0])
example: parent.$refs[0].$refs.anAccount

How can I access a parent element using selenium?

How can I access the parent of an element using Selenium?
For instance, I already have an inner element defined by class="angle". How to get an outer a element?
<i class="angle"></i>
You should try using xpath locator as below :-
using parent axes :
.//*[#class='angle']/parent::a
Or
.//*[#class='angle']/..
using child axes :
.//a[child::*[#class='angle']]

BeautifulSoup 4: select all divs with at least one child p tag with specific class

I'd like to extract a list of divs (including their children, for further processing) which contain one or more <p class="c8"> child tags, using BeautifulSoup 4, but I haven't had any luck using the CSS selector syntax. Can I use find_all and a boolean function, or is there a better way?
There are different ways to approach the problem. One, is to locate all p elements having class="c8" and find the parent div element:
for p in soup.find_all("p", class_="c8"):
div = p.find_parent("div")
You can also write a function to find all div elements checking that there is a desired child:
def filter_div(elm):
return elm.name == "div" and elm.find("p", class_="c8")
for div in soup.find_all(filter_div):
# do smth with div