I am creating automation that automatically sends messages through LinkedIn. The code is working fine, but as per our current requirement, I want to click on the attachment button so as to pass the attachment also with the text message. There are a few points that I have already tried:
Unable to fetch the element ID as its dynamic most of the time.
Don't want to use offsets (x,y) because once anyone changes the size of the window offsets changes.
Unable to use XPath.
Then I checked for another tool "UIVision" which makes a solution to capture that particular area (save it in a .png file) from the page where we want to click and during runtime it clicks there. So I tried searching image comparison API for java, tried with ASHOT and Sikulix too but none worked for me.
Anyone can help me with this?
When you say your unable to use xpath will you please elaborate?
The button has an id - it's attachment-trigger-ember1079.
If you're concerned about the latter part being dynamic, the attachment button also has a good title.
You can try using xpath string:
//button[contains(#title,'Attach a file')]
For me, on my linked in, this returns a unique hit on the expected attachment object:
If these don't work, there's also the option of using javascript to action the upload.
For more information on handling the upload dialog (after your identify the object) have a look here
Related
I want to use Selenium to interact with an element on a website. This element contains further content depending on the user's behavior, but obviously has exactly one HTML-element the whole time.
The element looks like this when the mouse is not on top of it:
When the mouse is on top of it, it looks like this:
When the user clicks on the down arrow, other content is visualized:
As you can see it contains even more logic, I didn't add screenshots for it though.
The corresponding HTML code is that, nothing more:
I do not know how this content is created. Does anybody know how I can use Selenium and java to interact with that web element? Selenium is obviously restricted to HTML content - what can I do without trying any dirty hacks like positioning the mouse at a certain position on the element myself to trigger the different visualization?
Update
I want to do automated end-to-end testing. That means I need to programmatically use the buttons of the web element as a user would:
Delete the date by clicking the x button
Alter the date by clicking up and down buttons
Alter the date by using the calender component
Changing the text in the web element (I guess I might already be able to do that with my current knowledge of Selenium)
I talked to the developer of that application and he told me he actually just adds one HTML input element of type date to the application. The rest (i.e. the renderer/editor of that input field as I presented in the question above) is totaly browser-specific. It looks like that in Chrome and entirely different in Firefox.
The above described web element seems to be the regular HTML 5 DateTime selection in Chrome. With that knowledge you can find the web element yourself and a tutorial for Selenium here: https://www.guru99.com/handling-date-time-picker-using-selenium.html and another discussion similar to my question here: How to set HTML5 type="date" input fields (e.g. in Chrome) using Selenium/Protractor?
The guru-page obviously describes how to control the full web element and it seems to work. I will check this out and accept this as the answer for now. Thanks everyone for your time!
My problem is as follows.
I am attempting to automate part of a test suite for a website I work in, and while most of it went well, I'm at the point where the developers added a lightbox to confirm the next action.
Using firebug I found out an xpath I could use to click the button I need to proceed, but sadly it isn't working.
After some manual attempts, I figured that pressing the "Space" key, I can proceed.
The problem is that any sort of try using "driver.findElement" be it by xpath, or link text, fails with a "No such element" error in console.
So I'm trying to just send the keypress of Space , without using find element.
To be clear, I want to emulate someone just pressing space without clicking or selecting anything beforehand.
I tried with driver.Keyboard... but "Keyboard" isn't recognized, so I'm at a loss of how to send this keypress without using driver.findElement.
The piece of code giving me problems is:
driver.findElement(By.xpath("//div[4]/div[3]/div/button")).click();
Any help would be appreciated.
Thank you and have a great day!
If you receive NoSuchElementException, but you know that the element is there, then it seems that the element get loaded into the DOM later (with ajax?), than the page get loaded.
In this case you should use Implicit or Explicit Wait to wait until an element present, or an element is visible, etc...
If it still doesn't work, and you want to try the Space Key thing, then you can perform it on any element, for example on the <body> tag:
WebElement body = driver.findElement(By.tagName("body"));
body.sendKeys(Keys.SPACE);
Hope it helps.
try this:
Actions action = new Actions(Driver);
action.SendKeys(Keys.Space).Build().Perform();
I'm trying to generate an xsl to be printed in a pre-printed sheet which works fine.
Now i want to give the user a better previsualization (in the pdf screen version) adding a background image which emulates the "pre-printed" stuf on the sheet to give the user a "context" of what is he printing.
The question is: Is there any way I can set a background image in xsl (using apache fop) visible only in pdf but not in the printed version of it?
Thank you all for reading or givin any advice.
Although as the comments state, you can't have content in the PDF that does not come out in a physical printed copy, here is one possible work around for you. Depending on how your users are ultimately going to be using FOP for PDF rendering and how your a driving the work flow, it's possible to pass a parameter into an xslt file before the transofrmation phase is run, so potentially, you could do a dual rendering of the same PDF, one that is presented to the user where the background image is enabled, and one that gets printed, you could just set a variable similar to how they do in this Example, and call it something like $isPreview, and just use a simple if or choose statement to check for 'Y' or 'N'.
Since you are sending to a printer, you may even want to take advantage of FOP's ability to generate to Postscript rather than PDF, I've used this feature quite extensively for print documents using FOP while also producing a PDF copy for electronic delivery via email or hosted services, and I've yet to find any discrepancy between the PDF rendering and what is printed after sending a rendered postscript file, so it should work well for you as well.
As I said, this is not truly a solution to your problem as you've presented it, but as a work around, it could get you the desired results if your clever about how you implement it.
I don;t think the statement that it is not possible is true, I am just not sure how to create such a PDF with FOP. Certainly you can add an image field. One would use a button field and place the image in the button. Then you would set the properties of that button to not print (printable false).
PDF support images in fields: https://answers.acrobatusers.com/adding-image-field-form-q41825.aspx
RenderX supports PDF Form fields but I do not see where they support an image inside the button, only text: http://www.renderx.com/reference.html#PDF%20Forms. But they do support setting a field to "printable".
I am working on a chat application where I am using a webView to show the conversation between sender and receiver and another webView to write the message which will contain text and emoticons (the reason for using webView is that it is capable to show emoticons along text using html), the 2nd webView is editable by setting its contenteditable property to true in html, now the problem is that when I drag and drop text or copy text from somewhere which contains formatting, links and images it will be shown with all the formatting that is why I want to disable dragAndDrop and pasting text from external sources such as browsers, if the text contains links then by clicking that link it will direct you to that page and the webView will become a web browser.
Tricky (i think). One way to do it is by providing your own EventDispatcher instance and intercept the actions you want to prevent, e.g. intercepting the DragEvent to prevent drops and the key events for the paste action. The downsides to this approach are, of course:
1) You'd have to code platform specific for the paste shortcut (CTRL+V vs. META+V)
2) If you want to disable pasting via the context menu this way, you'd have to prevent it from appearing at all. However I think in your case that would be intended.
So, pending a better a better solution I'd go with the dispatcher. Determine which events you want to be processed and forward those to the dispatcher chain. Consume the events you want to prevent.
I have an application which I am trying to test with WebDriver. On one page, the user selects a data source and some other options and then clicks next. When the user clicks next, they are presented with a page which has a list of documents that they must upload prior to submitting a request.
On the page with the documents that they must upload I am attempting to get the names of the documents and then compare them with a spreadsheet which has the list of required documents based on the data source the user chooses.
Here is my problem, I am trying to get the document names off the website. I first tried it with
String docOne = driver.findElement(By.xpath(/html/body/div[2]/div/div[2]/div/div[4]/div[2]/div/div/div/div/div[2]/div/div/div/h5)).getAttribute("textContent").toString();
System.out.println(docOne);
When I run this, it cannot find the element.
I then tried the following:
String docOne = driver.findElement(By.xpath("id('41027')/div[1]/h5")).getAttribute("textContent").toString();
System.out.println(docOne);
When I ran this, it could not find the element, I then manually tested this and found that every new request has a new ID, even though the first xpath I tested does not change.
My question then is, how do I get this to work? Since the element changes everytime I run the test?
I apparently had some brain flatulence this morning.
When automation clicks next to get to the documents page the page is scrolled all the way to the bottom and the top elements apparently cannot be found. I put a long delay 30 seconds and scrolled to the top of the page manually and the test passed with the first xpath I mentioned.
So I selected a web element which is always visible and told it to do a send keys with a page Up command, and it worked swimmingly.