So i am getting the path id('page-content')/x:div[6]/x:div/x:div/x:div/x:a[1]/x:img
How would i go about clicking the img?
I've tried
lol=find_element_by_xpath("//div[#class='emoji-items nano-content']//a[#title=':heart:']/img")
as well as
lol=find_element_by_xpath("//a[#title=':heart:']/img")
which i believe should work, but it instead gives me an error
What i did is: select all links elements (a) that contains heart in the title.
I tried to avoid using #title= because sometimes you might have issues due syntax used in the methods for finding the element or in other methods due to special characters like :.
The resulted path was:
//a[contains(#title, 'heart')]
If more elements are found you need to add another element in front of this to restrict the section that is searched in.
Related
I am doing QA and recently started using appium and cucumber to automate some tests and am still new to this.
I succeeded in what I wanted to automate using some functions like this one.
def function(element_name)
find_element(:xpath,
'//XCUIElementTypeOther[#name="' + element_name + '"]'
).click
end
This works for what I want, but now I am trying to redo the same functions but using contains. Something like this
def function(element_name)
find_element(:xpath,
'//*[contains(text(), element_name)]'
).click
end
What I'm getting is
An element could not be located on the page using the given search parameters.
I think I am just not using contains the right way but I am really not sure.
Xpath is not a good way for searching elements in Appium/XCUITest as it is often too slow and might not work as you expect it to work (your case with contains).
Instead you should you try XCUITest native locator strategies: iOSNsPredicate or iOSClassChain, e.g.
driver.find_element_by_ios_predicate("label contains 'Some text'")
You can check more examples here: python client tests, java client tests
the way you are using contains is correct, the only problem is its not finding the element.
If XPATH is not working , why dont you try with relative path e.g. below
def function(element_name)
//tbody//td[contains(text(),element_name)]
Bear with me, I am very new to this. I am writing in Python using Selenium Webdriver.
I have a test written out and I want to make an assertion to find is a class is present. I have tried multiple ways to go about to do this however i feel as though it is not working correctly.
I have attached a photo of the code I am looking at (the highlighted line) and this is what I have so far. This fires which is a pop up to notify a success the form was submitted.
self.assertTrue(driver.find_element(By.XPATH, '//*[#id="message-center"]/div'))
I would take advantage of the .find_elements method. It will return an empty list if no such elements are found.
self.assertTrue(driver.find_elements(By.XPATH, '//*[#id="message-center"]/div').count() > 0);
Any ideas Why sphinx is not creating cross reference links?
I have tried every possible combination to try to get a link to work, no luck.
I have tried with the napoleon_google_docstring on and off.
Other references that are create automatically are working ok.
You are using straight single quotes instead of backticks to delimit the role content. For example, :func:'atest' must be changed to :func:`atest`.
References:
http://www.sphinx-doc.org/en/latest/markup/inline.html
http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#interpreted-text
I use Vim+Ctags to write Python, and my problem is that Vim often jumps to the import for a tag, rather than the definition. This is a common issue, and has already been addressed in a few posts here.
this post shows how to remove the imports from the tags file. This works quite well, except that sometimes it is useful to have tags form the imports (e.g. when you want to list all places where a class/function has been imported).
this post shows how to get to the definition without removing the imports from the tags file. This is basically what I've been doing so far (just remapped :tjump to a single keystroke). However, you still need to navigate the list of tags that comes up to find the definition entry.
It would be nice it if it were possible to just tell Vim to "got the the definition" with a single key chord (e.g. ). Exuberant Ctags annotates the tag entries with the type of entry (e.g. c for classes, i for imports). Does anyone know if there is a way to get Vim to utilize these annotations, so that I could say things like "go to the first tag that is not of type i"?
Unfortunately, there's no way for Vim itself to do that inference business and jump to an import or a definition depending on some context: when searching for a tag in your tags file, Vim stops at the first match whatever it is. A plugin may help but I'm not aware of such a thing.
Instead of <C-]> or :tag foo, you could use g] or :ts foo which shows you a list of matches (with kinds and a preview of the line of each match) instead of jumping to the first one. This way, you are able to tell Vim exactly where you want to go.
I've just began learning Python and I've ran into a small problem.
I need to parse a text file, more specifically an HTML file (but it's syntax is so weird - divs after divs after divs, the result of a Google's 'View as HTML' for a certain PDF i can't seem to extract the text because it has a messy table done in m$ word).
Anyway, I chose a rather low-level approach because i just need the data asap and since I'm beginning to learn Python, I figured learning the basics would do me some good too.
I've got everything done except for a small part in which i need to retrieve a set of integers from a set of divs. Here's an example:
<div style="position:absolute;top:522;left:1020"><nobr>*88</nobr></div>
Now the numbers i want to retrieve all the ones inside <nobr></nobr> (in that case, '588') and, since it's quite a messy file, i have to make sure that what I am getting is correct. To do so, that number inside <nobr></nobr> must be preceded by "left:1020", "left:1024" or "left:1028". This is because of the automatic conversion and the best choice would be to get all the number preceded by left:102[0-] in my opinion.
To do so, I was trying to use:
for o in re.finditer('left:102[0-9]"><nobr>(.*?)</nobr></div>', words[index])
out = o.group(1)
But so far, no such luck... How can I get those numbers?
Thanks in advance,
J.
Don't use regular expressions to parse HTML. BeautifulSoup will make light work of this.
As for your specific problem, it might be that you are missing a colon at the end of the first line:
for o in re.finditer('left:102[0-9]"><nobr>(.*?)</nobr></div>', words[index]):
out = o.group(1)
If this isn't the problem, please post the error you are getting, at what you expect the output to be.