I'm going to try to explain this the best I can without making it too complicated. Currently I have a program which automatically grabs an element's locator (id, css, xpath) when I click on an element on a page.
The problem is, the element's css (ID, class name, etc) that I am grabbing is not unique (I cannot change the website)
I know in chrome, when I type $$('#test'), it will bring me a list of locators with ID 'test'. From there I know I could manually find the index of the element. However I want to do this automatically.
My application is essentially a recorder which captures the element locators. I am capturing the element event through selenium webdriver, but I am unable to get the index of that. I know this is a little confusing, but any help would be greatly appreciated.
By the way, I cannot use xpath.
Thanks.
Related
No such element
Help me to find the correct Xpath of the website etsy product table https://www.etsy.com/in-en/c/jewelry/earrings/ear-jackets-and-climbers?ref=catnav-10855
If you are looking for the whole table, then I believe the xpath you are looking for is:
//*[#class='wt-bg-white wt-display-block wt-pb-xs-2 wt-mt-xs-0']
As far as I can tell the table is the only element with that particular class combination, so I would use that to identify it.
If you use relative xpath it might break due to unforseen chances in DOM structure or css.
I am trying to click on the Financials link of the following URL using Selenium and Python.
https://www.marketscreener.com/DOLLAR-GENERAL-CORPORATIO-5699818/
initially I used the following code
link = driver.find_element_by_link_text('Financials')
link.click()
Sometimes this works and sometimes it doesn't and I get the Element is not Clickable at point (X,Y) error. I have added code to maximise the webpage in case the link was getting overlapped by something.
It seems that the error is because the webpage doesn't always load in time. To overcome this I have been trying to use expected conditions and wait libraries of Selenium.
I came up with the following but it isn't working, I just get TimeoutException.
link = wait(driver, 60).until(EC.element_to_be_clickable((By.XPATH,'//*[#id="zbCenter"]/div/span/table[3]/tbody/tr/td/table/tbody/tr/td[8]/nobr/a/b')))
link.click()
I think XPATH is probably the best choice here or perhaps class name, but there is no ID. I'm not sure if its because the link is inside some table that it isn't working, but it seems odd to me that sometimes it works without having to wait at all.
I have tried Jacob's approach. The problem is I want it to be dynamic so it will work for other companies. Also, when I first land on the summary page the URL has other things at the end so I can't just append /financials to the URL.
This is the URL it gives me: https://www.marketscreener.com/DOLLAR-GENERAL-CORPORATIO-5699818/?type_recherche=rapide&mots=DG
I might have find a way around this:
link = driver.current_url.split('?')[0]
How do I then access this list item and append the string 'financial/' to the list item?
I was looking for a solution when I noticed that clicking on the financial tab takes you to a new URL. In this case I think the simplest solution is just to use the .get() method for that URL.
i.e.
driver.get('https://www.marketscreener.com/DOLLAR-GENERAL-CORPORATIO-5699818/financials/')
This will always take you directly to the financial page! Hope this helps.
I apologize if this is a duplicate of a question already but nothing I read seemed to do the trick.
I am trying to automate the process of adding my hours for my job. This entails using selenium to mimic the process I do to enter the hours for me.
The problem is, as I navigate through the process, I have run into an instance where one of the elements has a dynamic id and xpath (any maybe other things. I am not very proficient in HTML).
I need to select the "Day" button on the "View" drop down. The highlighted HTML corresponds to that button. I have already checked and both the ID and Xpath change every time I create a new session. I usually do the following to find my elements:
elem = driver.find_element_by_xpath('xpath')
Below is the xpath I currently see:
//*[#id="ab5378a9418345a2a57ad12f066127a6"]
To further complicate things, the xpath for the "Week" selection is the following:
//*[#id="741015164c5547fbb5403c03c46636d3"]
I tried to figure out how to use "contains" with the xpath but even so, the two are not different enough to differentiate by using "#id". The only constant thing and difference I see each time is that the
data-automation-label="Day"
is present on the day element and
data-automation-label="Week"
is present on the week element.
Does anyone have any experience finding the elements when a problem like such occurs? I am working in Python3.6 on a windows 7 computer.
Again, I apologize if this is a duplicate but I tried very hard to find an answer before coming here for help.
Thanks in advance!
You can use two of the below possible selectors
XPATH
//div[#data-automation-label="Day"]
CSS
div[data-automation-label="Day"]
When you use identifier your main focus should be how to find something that is unique to that object. And it really doesn't matter if it is name or id or what not. Use what you think would work the best. And here data-automation-label implies that itself
Hello fellow Orcharders!
I'm not sure if what I want to do is possible, but I want to override the Driver for a single Field in the Module I'm writing.
The Field I want more control over is the Content Picker field. Basically I want the Content Picker to load the shapes for their respective content items. I've looked at Sipke's Content Picker Widget for an example on how to load shapes, however I'm unsure of the best/recommended approach to implement something similar in my module.
I have the Content Picker Field attached to my Content Part, and the default Content Picker comma list of Content Item titles appears as expected. I have tried to define an Alternate in Placement.info, but I can't load the Content Item shapes from within the Alternate view.
Presumably, as per Sipke's example, these shapes need to be built in the Driver and passed along. If this is correct thing to do, how could I do this in the most Orchard-y way with minimal "hacks". Looking into the debugger, I could "hack" my way to the Field I need in my part's Driver; but the module I'm building will be reused in the future by people unfamiliar with it, and if they start adding/deleting Fields from the Content Part, I'd like everything to behave accordingly!
Of course, if I must take the "hacky" option, I'm willing to do so, but only after I've exhausted all other options. This is my first module, and I've learnt an incredible amount along the way, and I'm really trying to learn the "right" way to build an Orchard Module as best I can.
Thanks in advance!
I'm trying to use JavaScript to find the context menu items being shown and selected from the lists (such as a document library) in SharePoint. I've tracked down a few different function names within core.js, (such as DispEx() and CMOpt()) but I really am having a hard time following the unhelpful variable name mess.
My understanding is that the context menu has to exist within the DOM somewhere - I just can't find out how to retrieve/reference it.
Thanks in advance - this is driving me nuts!
EDIT: I've tried traversing all children from onclick="return DispEx(...)" and I'm not getting anything! This is what I've used to capture that info:
' '
function findStuff(){
var something;
$('[onclick*=DispEx]').children().each(function(){
something = something + this.tagName + '\n';
});
alert(something);
}
It looks like those dom elements might be generated by javascript. Take a look at this article.
Also, you might be able to find the element id's by just searching the dom for text using the contains selector:
$(":contains('context menu item text')").attr('id')
I ended up using an element tracking plug-in to track commonalities between three different installations of SharePoint to get a rough general case. However, I was unable to avoid needed some configuration tailored to the install :(