I'm trying to extract the text from this Xpath in scrapy shell:
scrapy shell 'https://www.matterhorngotthardbahn.ch/de/stories/autoverlad-furka'
response.xpath('//*[#id="prita-medium-content"]/div[1]/div[2]/text()').getall()
it is the div class="rss-feed-description" content. However, it doesn't seem to work? anyone any idea why?
Related
I was trying to find out a dynamic element of a button from a html page with selenium
The syntax is given below
toggle=driver.find_element_by_xpath'//*[#id="__layout"]/div/div/nav/div/div[2]')
but I'm getting a syntax error as an output.
I'm using python and google chrome driver in this purpose. Also is there a better way to find dynamic elements, specially button elements?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver=webdriver.Chrome('C:/Users/Super User/PycharmProjects/webautomation/chromedriver.exe')
driver.get("abcd")
toggle=driver.find_element_by_xpath('//*[#id="__layout"]/div/div/nav/div/div[2]')
toggle.click()
AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'
Yup this is the problem now the complete code is given, and I want to click the button by the "xpath" or any other way.
Thanks for your quick response
I'm currently working on a node/express.js app for which I'm writing some e2e tests in nightwatch. Today I hit a roadblock while trying to search for an element using the XPath locator strategy. Basically I can search for elements using any of the following:
//div[#data-pino-name='userIdSection']
//input[#name="password"]
//input[#name="username"]
//button[#data-pino-name="submit"]
//a[#data-pino-name="cancel"]
By the way, all of the selectors above work fine using the chrome tools.
However, using the following:
//pre[#data-pino-name="requiredErrorMessage"]
doesn't work at all. I'm surprised since I expected the <pre> tag to be treated the same as any other html tag. However, the test returns a "element was not found" for all elements with the pre tag.
Anyone guidance would be appreciated.
You can follow this approach in writing XPath based on your scenario
//div[#data-pino-name='userIdSection']/pre
//div[#data-pino-name='userIdSection']/pre[#data-pino-name="requiredErrorMessage"]
Button HTML Code How would I write the command to click the xpath of a button?
the Xpath is
html/body/div[1]/div[1]/form/div/div[1]/div/div/a[1]/button
would it be
driver.findElement(By.xpath("html/body/div[1]/div[1]/form/div/div[1]/div/div/a[1]/button")).click();
Using XPath in this way is "easy" but is very fragile. You'd be better served getting the element in a different way, e.g. by CSS Selector "button.search-button".
driver.findElement(By.cssSelector("button.search-button")).click();
Learn more about CSS Selectors online. Here's a good reference guide, https://www.w3.org/TR/selectors/#selectors. There are many tutorials on the web, but here's a good one to start with, https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors.
I have a non standard tag in an HTML doc that I need to write a selenium test for.
Here is the tag: <evo:password>SomeText</evo:password>
And my selenium ide command I'm trying:
Command: storeEval
Target: xpath=/x:html/x:body/x:div/x:div[1]/x:div[2]/x:div/x:div/x:table/x:tbody/x:tr[2]/x:td[2]/x:strong/x:evo:password
Value: adminPass
Not sure what I need as my Target to get this to work and store the value between my tags.
I had to get creative with my selector. I ended up using a CSS selector and getting the last element with it.
css=strong:last
I'm sure you can also use :nth-child among other natural css selectors.
I'd like to be able to test the content in CKeditor using webdriver.
However there are some hurdles; firstly CKeditor uses Iframes, and there are several Iframes on the page, so not sure how to switch reliably to it using WebDriver as they don't have specific names.
In addition, the content inside the editor is within a <body></body> tag inside the iframe. I'm not sure how to get WebDriver to return the content reliably.
Has anyone actually tried to do this in their tests? If so, how did you achieve it?
Thanks.
You can use the CKEditor api and execute javascript. Not sure which selenium driver you are using but here is the java script you can use to get the HTML for:
"return CKEDITOR.instances['youreditoridhere'].getData();"
u may refer this
http://bharath-marrivada.blogspot.com/2012/03/fckeditor-switch-activeelement.html
hopes this help ;D