I don't know how I can use any elements to get clicked on this submit button.
I've tried it using xpath.,
web.find_elements_by_xpath('\\input value="submit" type="submit"').click()
but I get the error metioned in the title.
I searched and I couldn't find any solution.
Here's the inspected element by the browser:
What you pass to find_elements_by_xpath() doesn't looks like XPath. Also find_elements_by_xpath() should return you a list which doesn't have an attribute click(). Try to use below instead:
web.find_element_by_xpath('//input[#value="submit" and #type="submit"]').click()
Related
I need to extract an attribute "sub elemement" after initial selector.
I'm using this syntax as selector:
${first_video}= Get WebElement xpath:(//div[contains(#data-store, 'videoID')])[1]
This correctly give me this single element part:
<div class="alpha" data-store="{"videoID":"1234","playerFormat":"inline","playerOrigin":"video_home","external_log_id":null,"external_log_type":null,"playerSuborigin":"entry_point",
"useOzLive":false,"playOnClick":true,
"videoScrollUseLowThrottleRate":true,"playInFullScreen":false,"type":"video","src":"https:\/\/video.test.com\/v\/a\/123_n.mp","width":320,"height":180,
"videoURL":"https:\/\/www.test.com\/test\/videos\/12345\/","disableLogging":false}" data-sigil="Video">
</div>
My goal is to get the VideoURL attribute.
I've tried with
${first_video_link}= Call Method ${first_video} value_of_css_property data-store.videoURL
but it gaves me empty output.
Is there any specific syntax that I'm missing?
Many Thanks
Get the value of the data-store atrribute:
${val}= Get Element Attribute ${your locator}
It appears to be a proper json, so convert it to a python dictionary and then just access its key:
${as json}= Evaluate json.loads("""${val}""") json
Log To Console The videoURL is ${as json['videoURL']}
I am getting below error while executing below capybara command,
The interesting thing is the same XPath is not giving any error in I am expecting that XPath to be present.
But when I am trying to perform click on that XPath, it's throwing below error.
--------------code----------------
Then(/^I click on "([^"])" on left tree child of "([^"])"$/) do |child, parent|
within(:xpath, ".//div/span[#class='folder-nav-tree-fileroom' and text()='DND-IndexTwistyExpClps']/../../../../..", wait:5) do
find(:xpath, ".//span[contains(text(), '1 IndexTwistyLevel1')]/../../../span[#class='ui-tree-toggler fa fa-fw fa-caret-right']", wait:5).click
end
end
Error : Capybara::ElementNotFound: Unable to find visible xpath "//div[.//span[contains(text(), '1 IndexTwistyLevel1')]]/span[#class='ui-tree-toggler fa fa-fw fa-caret-right']"
Your code has a number of issues, which indicate it can't actually be working like you claim. If you fix the code and provide the HTML fragment it should be matching against we can narrow done to the issue, but for now the errors are:
Firstly, you have mismatched/non-escaped
's and )s in your XPath expressions (can't have inside a string surrounded bys so it's obvious you haven't copy/pasted your actual code)
Secondly, ::after is not valid XPath - ::after pseudo elements are purely CSS and can't be accessed from XPath, so including that in your selector isn't going to give the expected results. This should result in an invalid selector error being raised by Chrome.
Thirdly, by not starting your selectors with . you're completely defeating the within scoping block - see https://github.com/teamcapybara/capybara#beware-the-xpath--trap
Finally, using visible: false on an element you want to click makes no sense, since you can't click on an element that isn't displayed on the page.
Unfortunately its tough to tell which of these may be causing your actual issue (if any) since the code you have provided isn't valid.
within(:xpath, config['documents_obj']['FRChildTreeXpath'].sub('TEXT', parent), wait:5) do
elem = find(:xpath, config['documents_obj']['childTwistyXpath'].sub('TEXT', child), visible:false, wait:5).native
page.driver.browser.action.click(elem).perform
To avoid the error which iwas gettign what i simply did, is I used capybara action builder,
Take the native element then perform the action.
It worked perfectly in my case.
Reference : https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/ActionBuilder.html
I have various buttons and several buttons with the same name "Start". I need to click on the first found button with this name (innerHTML).
With jQuery this works with :
$('button:contains(Start):first').click()
How does it work with I.click()-Selector in CodeceptJS? I can't find the right syntax and always getting:
"invalid selector: An invalid or illegal selector was specified"
Here is the API for this function: https://github.com/Codeception/CodeceptJS/blob/master/docs/webapi/click.mustache
The only working solution I found is:
I.click('//button[1]');
But this solution is confusing, because you need to know the exactly number in the order of this element - and I have a lot of buttons with different names. Also this not allows me to search by innerHTML such as "Start".
You could use the I.executeScript like this:
I.executeScript("var elements = document.getElementsByName('Start');elements[0].click();"); or
I.executeScript("var elements =
document.querySelector(\"button[name*='Start']\");elements[0].click();");
You need using XPath for that
//button[1][contains(text(), 'Start')]
locate("//button[contains(text(), 'Start')]").first()
or
locate("//button[contains(text(), 'Start')]").at(1)
Works fine.
I am tring to find a button in a webpage using find elements, the page can contain one of the below button ID's.
driver.findElements(By.xpath("//*[contains(#id,'topBtn')]"))
driver.findElements(By.xpath("//*[contains(#id,'WSMplasticTop')]"))
driver.findElements(By.xpath("//*[contains(#id,'bottomApplyBtn')]"))
The above code is working as expected when i use the Firefox Driver, where as getting the below error when i run in Chrome Driver.
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[contains(#id='bottomApplyBtn')] because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[contains(#id='bottomApplyBtn')]' is not a valid XPath expression.
Just wanted to know whether i have done any mistake
Try to use
'//*[contains(#id,'bottomApplyBtn')]'
instead of
'//*[contains(#id='bottomApplyBtn')]'
When you are using contains method in your XPath expression, you basically are using an inbuilt method to find the element.
This method takes 2 parameters.
First the tag you in which you want to search.
Second is the actual text value which you are looking for inside the above tag.
Basically you have to call the method with 2 parameters and that 2 parameters should be comma separated.
So //*[contains(#id='bottomApplyBtn')] is wrong you should instead remove this = sign.
//*[contains(#id, 'bottomApplyBtn')]
|_______|____________________ Parameter 1
|__________________________________Parameter 2
Hope it helps!
Im trying to get the XPATH inside a iframe called "gadget_6"
i need the xpath of select div. Using selenium i do:
self.change_frame('__gadget_6') #Change to the correct iframe
after that, i try to do:
self.selec_orgvdc = self.driver.find_element(By.XPATH,'/html/body/div[5]/div/div/div/table/tbody/tr/td/div')
for posteriorly do:
self.selec_orgvdc.click
but i obtain the error:
InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression /html/body/div[5]/div/div/div/table/tbody/tr/td/div because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '/html/body/div[5]/div/div/div/table/tbody/tr/td/div' is not a valid XPath expression.
Someone can help me?
New modification:
self.change_frame('__gadget_6')
time.sleep(4)
self.logger.info("Buscando orgvdc")
#self.selec_orgvdc = self.driver.find_element(By.CSS_SELECTOR,'div.GN4Y2ATIMD table div.gwt-Label')
self.selec_orgvdc = self.driver.find_element(By.XPATH,'//div[5]/div/div/div/table/tbody/tr/td/div')
self.logger.info("Encontrado!")
Hi to work with xpath inside iframe first you have to sitch your driver instance ti that iframe then only you can perform any action
1.To switch to an iframe plz do it like : driver.switchTo().frame("selfservice");
Also looking at your source code i can clearly see there is 2 (two) i frames
1.iframe id = __gadget_6
2.iframe id = selfservice
hence i can guess why its not working in your case cause you are switching to a wrong i frame
now try this xpath //*[#class='GN4Y2ATIMD']/div/div/div/table/tbody/tr/td/div to perform click this will surely work.
XPath shouldn't include the /html/body. try this:
self.selec_orgvdc = self.driver.find_element(By.XPATH,'//div[5]/div/div/div/table/tbody/tr/td/div')
Note that this will be quite brittle. Even better would be to do something like this CSS:
self.selec_orgvdc = self.driver.find_element(By.CSS,'div.GN4Y2ATIMD table div.gwt-Label')