The scenario is:
Try to add experience in linkedin.
Then click on save button to save the added experience.
The below is html code for this button:
<button class="pe-form-footer__action--submit form-submit-action Sans-15px-white-100%" type="submit">
Save
</button>
I am trying to find it by xpath using:
#FindBy (xpath = "//*[contains(text(), 'Save')]")
WebElement saveExperienceButton;
Following screenshot may help:
I will appreciate your help.
if you do not mind css/xpath selectors that do not look very elegant, you can always open up Chrome developer tools on the website you wanna test with Selenium, mark the DOM elements you wanna access and in the context menu choose 'Copy xpath' or 'copy selector':
Try this xpath:
(//*[text()='Save'])[2]
On my profile there are 2 Save buttons - the second one is the skill save. Also, you might want to check this question for the contains syntax.
Creating an XPath using text is a less preferable way. instead of that use other attribute value which is unique.
for ex: in your case
//footer//*[contains(#class, 'form-submit')]
There is a button “Apply Now” on http://yearup.org.
Apply Now
So far I tried:
//*[#class='button']") (but there are 11 occurrences. Using [0] doesn't help
//*[#class='button']//*[text()='Apply Now']
"html/body/div/section[2]/header/section/ul/li/ul/div[2]/a"
.findElement(By.linkText("Apply Now"));
None of them worked for me.
Following error is obtained:
org.openqa.selenium.ElementNotInteractableException: Cannot click on element
What makes it a bit hard, is a duplicate of same tag in same page.
There are two solutions:
//div[#class='large-9 columns large-centered center-absolute']/a[#class='button' and contains(text(),'Apply Now')]
or
(//a[contains(text(),'Apply Now')])[2]
This will work:
driver.findElement(By.xpath(".//*[#href='http://www.yearup.org/seize-opportunity/']")).click();
If you are only trying to locate it and not click the element, then use this:
driver.findElement(By.xpath(".//*[#href='http://www.yearup.org/seize-opportunity/']"));
And further, if you are trying to travel to that page and you don't need to actually click on the element to travel there, just do:
driver.get("http://www.yearup.org/seize-opportunity/");
I know in the HTML it shows up as "Apply Now" but if you use
driver.findElement(By.linkText("APPLY NOW")).click();
it works. I just tested it.
I'm trying to click the link below:
<td id="mainleftlinkzoneover" class="mainleftlinks" width="151" title="Student Medicaid Eligibility">
Here's the code. It works with other links like this but not this one.
WebElement myElement = (new WebDriverWait(driver, 30))
.until(ExpectedConditions.elementToBeClickable(By.cssSelector("td[title='Student Medicaid Eligibility']")));
myElement.click();
Anyone have any ideas what I'm doing wrong?
you can do it by using the below code:
By.id("mainleftlinkzoneover") //here only id is used
or
By.cssSelector("#mainleftlinkzoneover[title='Student Medicaid Eligibility']") // this is another way to locate element
use the any one instead of your By.cssSelector.
Make sure there are no frame.
Is the link available for others to check? I mean can I test it if I want? you can give the url if possible.
here are my 2 cents:
I am thinking because of the spaces in your title, you might not be able to click on it.
I would try using contains
something like By.xpath("//td[contains(#title,'Eligibility')]") you can put either student or medicaid if they are unique. See if that helps.
I'm currently trying to automate test cases where I need to enter values for a required Text Area field.
The text area uses TinyMCE 3.4.9
I found a blog online that suggested
selectFrame (iFrame containing tinymce)
focus (tinymce)
type (tinymce, text)
that didn't help since Selenium RC can't locate the iframe. However, I tried this with the Firefox plugin and at the very least I can select the iframe and focus the editor, but I can't enter any text. With RC, nothing I do seems to work
I also tried entering text using the html editor. So selenium can emulate clicking the button to open the html editor, then RC would either fail to find the text area or I'll get an error such that the element is no longer attached to the DOM (something along that line)
Sorry if this sounds confusing.
This worked for me:
command: runScript
target: tinyMCE.activeEditor.setContent('Replace with your text')
Got it from http://www.tinymce.com/forum/viewtopic.php?id=27960
If you have multiple tinyMCE forms on one page, I recommend
Command: runScript
Target: tinyMCE.get('textarea_id').setContent('Your Text')
Firstly you switch to frame
// driver is type of IWebDriver
driver.switchTo().frame(frameName or frameIndex);
Then you get element by id and fill it with your text
var el = driver.findElement(By.id("tinymce"));
el.sendKeys("YOUR TEXT");
WebElement bodyIframe = driver.findElement(By.tagName("iframe"));
driver.switchTo().frame(bodyIframe); WebElement mce =
driver.findElement(By.id("tinymce")); mce.sendKeys("This is for testing!!!!");
This worked perfectly for me
The only way I am able to get Selenium testing to work with TinyMCE is to not use TinyMCE for the test.
Use some server-side wizardry to selectively disable the TinyMCE plugin under test conditions.
This will not help you with testing the use of TinyMCE itself, but you will at least be able to fill in the form to completion and move your tests forward... :)
For TinyMCE 3.4.x and Selenium IDE in Firefox, this is working for me. Substitute the id of your TinyMCE instance for NAME below:
<tr>
<td>type</td>
<td>dom=document.getElementById('NAME_ifr').contentDocument.body</td>
<td>Editor content</td>
</tr>
This is based on https://gist.github.com/809728
We use the process described at techiebyday.blogspot.com, and it works great in current versions of Selenium RC (at least up to 2.20) and TinyMCE (post-3.4). In C#, it looks like this:
string editorFrameId = editorId + "_ifr";
selenium.Focus(String.Format("dom=document.getElementById('{0}').contentWindow.document.body", editorFrameId));
selenium.GetEval(String.Format("selenium.browserbot.getCurrentWindow().document.getElementById('{0}').contentWindow.document.body.innerHTML = '{1}';", editorFrameId, fillString));
I've been trying to use this solution:
<tr>
<td>type</td>
<td>dom=document.getElementById('NAME_ifr').contentDocument.body</td>
<td>Editor content</td>
</tr>
Replaced 'name_ifr'. First to frame name and inserted before entering into the tinymce frame and then replaced name with 'tinymce' and inserted after entering the frame where accoring to all the rules typing must happen. But all I get is errors. Somehow, I never make DOM or js commands work in my script. Is there something I am missing?
If you have one TinyMCE element in page:
var obj = ((IJavaScriptExecutor)webDriver).ExecuteScript("tinyMCE.activeEditor.setContent('" + text + "');");
I was having problems entering text in a tinyMCE editor too:
FireFox 20.01
tinyMCE 3.4.9
Selenium IDE 1.10.0
I have multiple tinyMCE editors in my form.
Solution (using Selenium IDE, which can be ported to Selenium RC easily):
Using firebug, find out the id of the tinymce iframe that replaces the textarea, e.g.
form_editor1_ifr
Strip the "_ifr" from this id to get the id of the original textarea
Use this id in the target for the runScript command in Selenium IDE:
tinyMCE.get('form_editor1_ifr').setContent('the content');
In Selenium webdriver PHPUnit_Extensions_Selenium2TestCase, this works when you use:
$this-> execute(array('script' => "tinymce.get('cms_cpg_content').setContent('Lorem ipsum dolor sit amet,...')", 'args' => array()));
When you want to add text.
I was able to solve this problem using Selenium RC, have done following steps(attached screenshot for your referral)
on tinyMCE editor, click on Advanced option icon
Click on "<>" source code icon
Source code popup appears, enter text and click Ok
text appears in TinyMCE editor
Just for your reference I have given steps with CSS locator
click on advaced option button: css= tr[id*='tinymce'] td * div[aria-label='Advanced Options'] button
click on source code: css= tr[id*='tinymce'] td * div[aria-label='Source code'] button
click on popup textarea css= div[class*='mce-floatpanel'][aria-label='Source code'] * textarea
click on ok button on popup css= div[class*='mce-floatpanel'][aria-label='Source code'] * div>button:contains('Ok')
verify text present in tinymce css=body p:contains(this is testing)
Hope this will solve your problem :)
http://odino.org/typing-into-tinymce-with-selenium/ ...looks like TinyMCE and selenium IDE hook ups don't work on 3.4.5, so my presumption is that this issue has been carried over into 3.4.9.
I am having a problem clicking on a link within htmlunit. I went through the api on the site(which I didn't really understand well) and looked at all the sample code I could find and am still having a problem with clicking on links.
Here's the top of the error messsage(its pretty large, if you want I can submit it all)
"page2 = link2.click() Exception class=[net.sourceforge.htmlunit.corejs.javascript.JavaScriptException] com.gargoylesoftware.htmlunit.ScriptException: Sys.ArgumentOutOfRangeException: Sys.ArgumentOutOfRangeException: Value must be an integer. Parameter name: x Actual value was Infinity. "
The first page loads fine but when I click on the second link, I get this error(the link is javascript). Here's parts of my code
page = webclient.getPage(url)
anchors1 = page.getAnchors()
for anchor in anchors1:
if anchor.asText() == "2":
link2 = anchor
break
page2 = link2.click()
If I do a print link2 I get: HtmlAnchor[<a href="javascript:__doPostBack('ctl00$MainContent$gvSearchResults','Page$2')">]
At first I thought maybe the HtmlAnchor was a problem and I had to remove it but then I looked at other sample code and they seem to have their links end up in the same format and it works.
So confused..please help :-)
Thanks in advance!
The problem is not in the code used to click on the link. It's in the JavaScript executed when the link is clicked. Either the JavaScript is buggy, or the JavaScript interpreter used by HtmlUnit has a problem running it.
The problem seems to be with a parameter x which has the Infinity value during the execution.