I have the following <p> tag wrapped in <div> tag using selenium Webdriver and I would like to get the <p> tag content using node.js
<div id="guideContainer-rootPanel-HouseholdContact-guidetextbox___guideFieldShortDescription" class="guideFieldDescription short" style="null;display:none">
<p>Enter the first name of the contact person.</p>
</div>
Related
After upgrading to SAP Commerce 2105 Patch 13 from 1811, components with type CMSParagraphComponent do not have img, span HTML tags and HTML tag attributes like class, style.
Before upgrade HTML was displaying in the page as following:
<div class="content">
<div class="size-guide__area active" data-js="size-guide-area">
<div>
<div class="size-guide__close" data-js="size-guide-close">
My text
<span class="icon-close-circle"></span>
</div>
</div>
</div>
</div>
My component is covered with <true class="yCmsComponent"></true> after upgrade somehow.
After upgrade HTML is displaying as following:
<true class="yCmsComponent">
<div class="content">
<div>
<div>
<div>
My Text
</div>
</div>
</div>
</div>
</true>
impex:
INSERT_UPDATE CMSParagraphComponent;$contentCV[unique=true];uid[unique=true];name;&componentRef;content[lang=$lang];
;;chartParagraph;Chart Paragraph;chartParagraph;"<div class='size-guide__area' data-js='size-guide-area'>
<div>
<div class='size-guide__close' data-js='size-guide-close'>
My text
<span class='icon-close-circle'></span>
</div>
usage in tag file:
<cms:component uid="chartParagraph" evaluateRestriction="false"/>
CMSParagraphComponentRenderer class is sanitizing HTML. Rules are defined in HtmlSanitizerPolicyProvider class. It is checking a property before sanitizing. I solved issue by changing the property in storefront extension. You may customize HtmlSanitizerPolicyProvider class to have a safer solution. Changing following property may cause an issue, it is not the safest solution.
In the project.properties file of the storefront extension, add following property.
cms.components.allowUnsafeJavaScript=true
I'm totally new to programming. Currently trying to automate few daily tasks using selenium web driver on Python. I have a webpage which contains multiple + expand button. Below is the code
Without expansion:
<div class="expansion container">
<div class="expansion_base_parent"></div>
<div class="expansion expansion_parent">
<button type="button" class="compact-visual-toggle"></button>
</div>
</div>
With expansion
<div class="expansion_container">
<div class="expansion_base_parent"></div>
<div class="expansion expansion_parent">
<button type="button" class="compact-visual-toggle active"></button>
</div>
</div>
I'm unable to find this element using any of the find_by method
My colleague said the page contains json that's why unable to locate using find_by
Can somebody please help with the code to locate and click the expand button.
Actual page:
Go-to https://fortigate.fortidemo.com
Username demo
Password demo
Click login read-only
Click later in next window
Now navigate to Network > interfaces There you can see lot of expand button that's what I'm referring I have written code to come till this page, but I want to expand before taking screenshot of the page
It does not have to do anything with JSON.
See, you are saying
<div class="expansion container">
<div class="expansion_base_parent"></div>
<div class="expansion expansion_parent">
<button type="button" class="compact-visual-toggle"></button>
</div>
</div>
that you see this HTML when expand button is present.
You can locate with below css :-
button.compact-visual-toggle
or xpath :
//button[contains(#class, 'compact-visual-toggle')]
and since you have mentioned that they are multiple expension button, you can differentiate like below :
(//button[contains(#class, 'compact-visual-toggle')])[1]
should represent the first, for second you can try :
(//button[contains(#class, 'compact-visual-toggle')])[2]
and so on.. for 3rd, 4th....
in code you can use it like this :
driver.find_element_by_xpath("//button[contains(#class, 'compact-visual-toggle')]").click()
or
driver.find_element_by_xpath("(//button[contains(#class, 'compact-visual-toggle')])[1]").click()
or
driver.find_element_by_xpath("(//button[contains(#class, 'compact-visual-toggle')])[2]").click()
Now, coming to second part :
<div class="expansion_container">
<div class="expansion_base_parent"></div>
<div class="expansion expansion_parent">
<button type="button" class="compact-visual-toggle active"></button>
</div>
</div>
in you you want to un-expand it, you could use the below xpath :
//button[contains(#class, 'compact-visual-toggle active')]
and use it like above.
I want to get a link in html path, the codes are here:
<div class="btn btn-primary btn-lg">
<a href="https://storage.googleapis.com/audiog-204018.appspot.com/files/hello1574358335.mp3">
Download MP3 </a>
</div>
How can i get this link with selenium
In Python Selenium you can simply use element.get_attribute()
So in your case, it should just be
element.get_attribute("href")
I want to get the href attributes from the given HTML code so that i can go inside the link and scrape some data from it.
<div class="cb-col cb-col-67 cb-rank-plyr"> <a class="text-hvr-underline text-bold cb-font-16" href="/profiles/1643/aaron-finch" title="Aaron Finch's Profile">Aaron Finch</a> <div class="cb-font-12 text-gray">AUSTRALIA</div> </div>
<div class="cb-col cb-col-67 cb-rank-plyr"> <a class="text-hvr-underline text-bold cb-font-16" href="/profiles/10863/fakhar-zaman" title="Fakhar Zaman's Profile">Fakhar Zaman</a> <div class="cb-font-12 text-gray">PAKISTAN</div> </div>
I want to get the attributes of href and save it to a list.
You can use regular expressions to parse out thinks in the HTML such as that href tag.
Here is an article explaining that: https://medium.com/#tracy_blog/regex-and-selenium-2c5a89f23a17
To accomplish this, I would consider using get_attribute(name) over a regular expression.
I am trying to automate a process using Python and selenium webdriver.
I am able to login successfully and navigating to the page where I want to post something but for some reason the xpath is not recognized by the system.
It gives the below error:
NoSuchElementException: Unable to locate element: //*[#id="widecol"]/div/form/p[1]/input
Here is my code:
from selenium import webdriver
mydriver = webdriver.Firefox()
mydriver.get("https://www.phishtank.com/")
mydriver.maximize_window()
mydriver.find_element_by_xpath('//*[#id="username"]').send_keys("myusername")
mydriver.find_element_by_xpath('//*[#id="password"]').send_keys("mypassword")
mydriver.find_element_by_xpath('//*[#id="header"]/div[2]/form/input[3]').click()
mydriver.find_element_by_xpath('//*[#id="nav"]/ul/li[2]/a').click()
mydriver.find_element_by_xpath('//*[#id="widecol"]/div/form/p[1]/input').send_keys("sample text testing to fill form")
This is my HTML code
<div id="widecol">
<div class="padded">
<form method="POST">
<h2>Add A Phish</h2>
<ol>
<li>Visit our <b>What is phishing?</b> page to confirm that the suspected phish meets all of the criteria.</li>
<li>Add a phish using the form below, or even better, submit a phish directly via email.</li>
</ol>
<h3>Phish URL:</h3>
<p>
<input type="text" name="phish_url" style="width:90%;" value="" /><br />
<span class="small">Copy and paste the URL of the phishing website.</span>
</p>
<h3>What is the organization referenced in the email?</h3>
<p class="slim">
<select name="phish_target">
which gives me the following error:
NoSuchElementException: Unable to locate element: //*[#id="widecol"]/div/form/p[1]/input
Here is the HTML code:
<input type="text" name="phish_url" style="width:90%;" value=""> outer HTML code
And this is my XPath:
//*[#id="widecol"]/div/form/p[1]/input - Xpath
Please let me know where to look, thank you.
You need to induce WebDriverWait for the element to be clickable and you can use the following line of code :
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#name='phish_url' and #type='text']"))).send_keys("sample text testing to fill form")
Without the full HTML, we can't tell if the XPath is correct or no.
Can you please try and include more outer Html code?
You can try and wait after clicking on that last URL, maybe the element wasn't loaded yet.
You can also check if the input is in an iframe, that might be causing the problem.
Could you try the following instead?
//*[#id='widecol']//input[#name='phish_url']
Should work for that input. Just for trial/error sake, try a small wait before doing this.
The new Selenium version doesn't allow it.
Try the below code
from selenium.webdriver.common.by import By
And then Change the 'find_element_by_xpath statements' to
mydriver.find_element(By.XPATH,'//[#id="username"]').send_keys("myusername")
You can refer to the link to know more