how to upload a file using firefoxdriver in selenium testing - firefox

i want to upload a gif file in my application using selenium codes in firefox,
i have the following file input type:
<input id="file" type="file" size="27" value="Attach document" onclick="javascript:return processAttachment();" name="file">
i have tried this code:
driver.findElementByName("file").sendKeys("E:/plus.GIF");
driver.findElementByName("file").click();
but its is not working, instead a file upload window is opening, can any one help me getting out of it.please
thank you

With this line driver.findElementByName("file").click(); you are "trying" to click the field , where you typed the text.It should be driver.findElementByName("NAME OF THE SUBMIT BUTTON").click();

Related

issue with laravel jetstream triggering profile image explorer twice (Livewire & AlpineJs)

Good day Developers
I have this code that comes built in laravel jetstream:
input:file
<input type="file" class="hidden"
wire:model="photo"
x-ref="photo"
x-on:change="
photoName = $refs.photo.files[0].name;
const reader = new FileReader();
reader.onload = (e) => {
photoPreview = e.target.result;
};
reader.readAsDataURL($refs.photo.files[0]);
"/>
and explorer trigger:
<x-jet-secondary-button class="mt-2 mr-2" type="button" x-on:click.prevent="$refs.photo.click()">
{{ __('Select A New Photo') }}
</x-jet-secondary-button>
When I click on the button, it shows the explorer, the problem is that after selecting the image I want to upload, it reopens the file explorer again (Then I have to select the very same image for the second time) before it can successfully upload the image.
I tried searching the net for a solution but I'm really new to alpine and livewire I couldn't come to a solution.
If anyone can point out where the issue is, I'd appreciate it.
Thank you in advance.
I got the same problem loading livewire twice, in my case, i was importing another js file in resources/app.js which is imported by the app's webpack-mix.js. And that additional file had a copy of resources/app.js, effectively loading Alpine twice and triggering events twice. After i removed the import, events fired only once.

Unable to click OK button in pop-up in webdriver using ruby

Unable to click on OK button
I tried like this but it is not clicking.
b.find_element(name: "OK").click #----> it is not clicking
How to interact with this type of pop-us in ruby.
<input class="copybutton" type="button" title="Copy" onclick="copyErrText()" name="copy" value=""/>
<!-- *** Added: copy button *** -->
<button class="button" onclick="disp()" name="OK" value="OK" type="button">OK</button>
You can try one of the following it may help you.
ele = find_element(name: "OK")
driver.action.move_to(ele).click(ele).perform
or
driver.execute_script("arguments[0].click();",ele)
or
driver.execute_script("disp();")
You've tagged this Watir, but your syntax is Selenium. If you are using Watir, it would look like this:
browser.button(name: 'OK').click
If there are funky javascript things going on, you can fire an event to interact with it. Use this power sparingly.
browser.button(name: 'OK').fire_event :click
Hope this helps.
driver.switch_to.alert.accept

Error when trying to set text_field using watir-webdriver and chrome

I'm using cucumber with ruby and watir-webdriver. I've not had this issue before and text_fields on other pages work fine. I've tried using CSS & name instead of ID but no luck. Does anyone have any ideas on what's causing this and how to get around it in Chrome?
The error does not occur when using Firefox.
Script:
#session.text_field(:id, 'officialTitle').when_present.set("Test 1")
html:
<input id="officialTitle" name="official_title" server-validation="" class="form-control ng-pristine ng-invalid ng-invalid-required ng-touched" ng-model="profile.study.official_title" required="" type="text">
Error:
Selenium::WebDriver::Error::UnknownError: unknown error: a.tagName.toUpperCase is not a function
(Session info: chrome=46.0.2490.80)
(Driver info: chromedriver=2.17.340128
(994135a3538dd99439ef22cea8a9b098e00d8eb4),platform=Mac OS X 10.11.0 x86_64)
Turns out another element with the ID tagName was causing the issue, even though that element was not being interacted with. Changing that ID resolved my issues.

Automation using Watir button elements

So I have been experimenting with Watir automation scripts using Ruby. I have tried to experiment with different websites, like Twitter, Gmail, and Yahoo. Here is the catch: I am able to open a browser, login, and get to the home page. On all of these whether it is compose a new email or tweet every time I select it with the appropriate ID or Class, it throws an error in the terminal like this...
.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:533:in assert_element_found': unable to locate element, using {:title=>"compose", :tag_name=>"button"} (Watir::Exception::UnknownObjectException)
from /Users/xxx/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:505:inassert_exists'
from /Users/xxx/.rvm/gems/ruby-2.2.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/elements/element.rb:114:in click'
from yahoo_mail.rb:18:incompose_email'
from yahoo_mail.rb:27:in `'
My question is, are there elements that you simply cannot click or select using Watir automation?
EDIT: How would I be able to hit this to be more specific? I seem to be getting the same results on Yahoo, Gmail, and Twitter when it comes to composing anything after getting logged in. So I how would I hit this button?
button id="global-new-tweet-button" type="button" class="js-global-new-tweet js-tooltip btn primary-btn tweet-btn js-dynamic-tooltip" data-placement="bottom" data-component-term="new_tweet_button">
The HTML for the Compose button is basically the following (NOTE: id attribute removed):
<button tabindex="0" data-action="compose" title="Compose" class="btn btn-compose">
Your stacktrace indicates that you're using this locator:
{:title=>"compose", :tag_name=>"button"}
If you change :title=>"compose" to :title=>"Compose", you should be in business.
Have you tried the following code?
button(id:'global-new-tweet-button').when_present.click
Maybe you were clicking the button without checking if it is already present on the page.

NPAPI plugin not working in Firefox5.0 on Mac

I have a NPAPI plugin (built using firebreath) which works fine Safari and Google Chrome (both on Mac); But it fails to work on Firefox.
When I looked at the Firefox plugins (about:plugin) it correctly shows my plugin name and version and shows it as Enabled.
Following is the code I use to load the plugin in javascript -
<object name="fp" type="application/x-myplugin" width="0" height="0">
<embed name="jsPlugin" id="jsPlugin" width="0" height="0" type="application/x-myplugin">
</embed>
</object>
And I use this plugin as follows -
function PluginVwersion(){
var jsPlugin = document.getElementById('jsPlugin');
jsPlugin.GetScannerDetails();
}
But whenever I test this code in firefox, it doesn't work, and I see following error in the Error Console -
Error: jsPlugin.GetScannerDetails is not a function
Source file: file:///Users/u162794/Desktop/test.html
Any help is appreciated.
Regards,
Yogesh Joshi
Why exactly are you trying to use an embed tag inside an object tag? Remove the embed tag, set your object tag id to jsPlugin, and then try it.
<object id="jsPlugin" type="application/x-myplugin" width="0" height="0"></object>
Also try using the example FBControl.htm file that is created in the build/projects//gen folder in your project like is suggested on the FireBreath website.

Resources